PRB: Windows Flash and Disappear in Dialog-Based ApplicationsLast reviewed: December 11, 1997Article ID: Q138681 |
The information in this article applies to:
SYMPTOMSIn a default dialog-based application, windows created after returning from DoModal flash and disappear.
CAUSEIn an MFC application when the main window associated with the application is destroyed, a WM_QUIT message is posted to the application. This message is posted by calling AfxPostQuitMessage from CWnd::OnNcDestroy for the main window. AfxPostQuitMessage calls PostQuitMessage, which performs some processing and then posts the WM_QUIT message to the application. The PostQuitMessage function indicates to Windows that a thread has made a request to terminate. Any window that is created after calling the PostQuitMessage function will be immediately destroyed. The effect is that the window flashes for a brief moment and then disappears. If DoModal is called to display another modal dialog box, control returns immediately from this function.
RESOLUTIONChange the line that sets the m_pMainWnd to point to dialog object, into a comment. Or set m_pMainWnd for the CWinApp-derived object to NULL before control gets to CWnd::OnNcDestroy for the dialog object. One way of doing this is to override OnNcDestroy for the CDialog-derived object. In the overridden function, set the m_pMainWnd to NULL before calling the base class.
STATUSThis behavior is by design.
MORE INFORMATIONThe following code can be implemented in the CDialog-derived class to prevent PostQuitMessage() from being called when the dialog box in a default dialog-based application is dismissed.
Sample Code to Resolve Behavior
void CMyDialog::OnNcDestroy() { AfxGetApp()->m_pMainWnd = NULL; CDialog::OnNcDestroy(); } |
Additional query words: messagebox
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |