对话框已经不显示了,但对话框还没有退出: 程序在app中等主对话框退出: m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK)
断点进入OnCancel可发现在OnCancel();内部调用的是::EndDialog(m_hWnd, nResult);再看MSDN上对EndDialog的说明:EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box. 因此可以猜出原因应该就在这里。
OnClose()是响应 WM_CLOSE 的.一定程度上可以说CDialog::EndDialog()和OnClose()完成类似的工作,但处理的机制不一样,前者是CDialog的对象机制,后者是WM的消息映射机制。所以你OnCancel只是关闭了你之前的对话框,然后又模态的显示了另一个对话框,当这个对话框关闭后,系统才会调用进行销毁工作
程序在app中等主对话框退出:
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
因此可以猜出原因应该就在这里。