MFC 退出程序方法

一、對話框用   CDialog::OnOk();   
     Doc/View用 OnClose();

二、PostQuitMessage(0);//最經常使用

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

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

三、ExitProcess(0);注意使用時先釋放分配的內存,以避免形成內存泄露

四、exit(0) 正常終止程序; exit(非0)非正常終止程序

五、OnClose();

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

相關文章
相關標籤/搜索