Q: The program is based on the dialog box, I display two dialog boxes, one behind the other, here is my practice:
CMyApp::InitInstance ()
{
...
CMyDialog1 dlg1;
m_hMainWnd = &dlg1;
int result = dlg1.DoModal ();
CMyDialog2 dlg2;
result = dlg2.DoModal ();
...
}
In the above code, first a dialog box is appropriately invoked, but the second dialog box does not, for example, invoke Dlg2. DoModal () returns-1, and when I step through it I find that wm_quit is added to the message queue and I don't know why.
A: 1 because MFC needs M_HMAINWND member functions must point to an object with a valid window handle, if not, it will send itself wm_quit message to interrupt itself.
2 I know why, when you set m_pMainWnd point to Dlg1, MFC thinks your Dialog1 is the main window. When the user closes the dialog box, MFC thinks the user wants to quit the program because the m_pMainWnd point to the window is closed.
You think it's not working because the application exits after two DoModal () calls. InitInstance () will return to m_pMainWnd has already been used in the wizard and you cannot use it as you do.