As an exercise, I'm trying to write a 100% correct Windows program. To that end, I'm checking the return values of every Win32 API call I use and report to the user if there are any problems.
This generally works fine until the program starts to close... for example:
case WM_CLOSE:
{
MessageBoxA( NULL, "Foo", "Testing", MB_OK );
DestroyWindow( hWnd );
MessageBoxA( NULL, "Bar", "Testing", MB_OK );
break;
Displays Foo but not Bar. I've observed that any MessageBox after DestroyWindow will not render.
I understand the technical reasons for this... My question for StackOverflow is: In a Win32 Desktop C program, what is the best mechanism/design to inform the user about something (Boo, Program ended successfully, whatever...) at the end of the program?
Ideally, I'd like to be able to display a MessageBox just before wWinMain terminates.
Thank you!
Without seeing the rest of your code, I would guess that you are handling
WM_DESTROYto callPostQuitMessage().If so, then
WM_DESTROYwill be processed whileDestroyWindow()is still running, thusWM_QUITwill be posted before the 2nd call toMessageBox()is made.The internal message loop inside of
MessageBox()will thus pick up theWM_QUITmessage and discard its dialog window. And, being a good modal dialog function,MessageBox()will re-post theWM_QUITmessage so that other message loops higher up on the call stack (like yours) will still be able to exit correctly, thus letting your app terminate correctly.So, what is stopping you from doing so? Simply do it after your message loop has already handled the
WM_QUITmessage, eg: