这个神奇的MessageBox()我是写在这个位置的,MFC工程的APP类的InitInstance()里—— CtestMFCDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用
//  “确定”来关闭对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用
//  “取消”来关闭对话框的代码
}
int iMBRet = MessageBox(NULL, _T("123"), _T("abc"), MB_ICONWARNING);
int iLastErr = GetLastError();
大家可以试试,好好玩的,这里的MessageBox()会秒过。iMBRet == 1,iLastErr == 0。
请教大家原因,谢谢!

解决方案 »

  1.   

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
      

  2.   

    不懂
    // for 回复内容太短了!
      

  3.   

    if (nResponse == IDOK)
        {
            // TODO: 在此放置处理何时用
           ; //  “确定”来关闭对话框的代码
        }
        else if (nResponse == IDCANCEL)
        {
            // TODO: 在此放置处理何时用
            ;//  “取消”来关闭对话框的代码
        }
      

  4.   

    INT_PTR nResponse = dlg.DoModal();
    DoModal()函数返回之后,m_pMainWnd为NULL了,MSDN上这样描述:
    If this data member is NULL, the main window for the application's CWinApp object will be used to determine when to terminate the thread. m_pMainWnd is a public variable of type CWnd*. 主线程结束,进程即将退出了
      

  5.   

    >>请教大家原因,谢谢!
    当调用MessageBox 时,此时应用程序已经在“终止的”
    所以应用程序会强制终止MessageBox 框
    具体原因,可以看看msdn对m_pMainWnd 成员的解释:
    Use this data member to store a pointer to your thread’s main window object. The 
    Microsoft Foundation Class Library will automatically terminate your thread when the 
    window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated. If this data member is 
    NULL, the main window for the application’s CWinApp object will be used to determine 
    when to terminate the thread. m_pMainWnd is a public variable of type CWnd*.
      

  6.   

    INT_PTR nResponse = dlg.DoModal(); 已经停在这了.. 到MessageBox的时候这个程序已经退出了.. 所以..