About dialog boxes

Source: Internet
Author: User
Tags message queue

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.