15,980
社区成员




导致第二个窗口立即退出,是因为这两句代码的上一段:
// pump message, but quit on WM_QUIT
if (!AfxGetThread()->PumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
MSG msg;
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::MessageBox(NULL, " ButtonOK is Clicked", "Message:", MB_OK);
}
CMfc1Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
MSG msg;
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
MessageBox(NULL,"OK pressed","info",MB_OK);
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
MSG msg;
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
MessageBox(NULL, " ButtonCancel is Clicked", "Message:", MB_OK);
}