VC中退出应用程序-几种很有用的方法

来源:互联网 发布:koala软件 编辑:程序博客网 时间:2024/06/05 20:22

VC中退出应用程序-几种很有用的方法


1、对话框用   CDialog::OnOk();   
     Doc/View用 OnClose();

2、PostQuitMessage(0);//最常用

     PostMessage(WM_QUIT,0,0);//最常用

     ::SendMessage(AfxGetMainWnd()->m_hWnd,WM_CLOSE,0,0);//最常用
     ::PostMessage(AfxGetMainWnd()->m_hWnd,WM_CLOSE,0,0);//最常用

3、ExitProcess(0);注意使用时先释放分配的内存,以免造成内存泄露

4、exit(0) 正常终止程序; exit(非0)非正常终止程序

5、OnClose();

void CMainFrame::OnClose() 
{
        // TODO: Add your message handler code here and/or call default
       if (MessageBox("确定要退出吗?","提示",MB_YESNO|MB_DEFBUTTON2)==IDYES)
       {
                CFrameWnd::OnClose();
       }
}

原创粉丝点击