MessageBox is not shown after Dialog was closed in MFC Dialog Application

In Win32, you can not show MessageBox after calling PostQuitMessage() until calling GetMessage to get out of message loop.

In MFC dialog app, the dialog is set to m_pMainWnd and when dialog is closed, PostQuitMessage is called. If you want to show MessageBox after the dialog closed, there is two method to do this.

Method 1, Keep m_pMainWnd to NULL.
Comment out the following line so that m_pMainWnd is not set.

m_pMainWnd = &dlg;

Method 2, Call PumpMessage to call GetMessage.
Calling PumpMessage until it returns false. After that you can show MessageBox.

while(PumpMessage())
    ;

Leave a comment

Your email address will not be published. Required fields are marked *