OH MY GOSH!
I can't believe this was just posted here!
I came here for a different reason today, but then I saw this thread in the "Recent Threads" section. I ran into the exact same problem just last night!
I was creating a window, then deliberately throwing an exception to see how my app responded to error conditions. The window was stored in a automatic-type HWND wrapper, so when the exception fired, DestroyWindow was automatically called for it.
I found that when I caught the exception, and tried to display a message box, the box wouldn't show. This only occured after the window was created, though. If I threw the exception just before the window was created (AND stored in the automatic wrapper), the box would pop just fine. If I created the window, but didn't put it into the wrapper, it would work also, though that would leak the window.
Eventually I figured it must've been something with the message loop. I moved my PostQuitMessage( 0 ); from my WM_DESTROY handler to WM_CLOSE, but after I called DestroyWindow:
// initial handlers://-------------------------case WM_CLOSE: DestroyWindow( hWnd ); return 0;case WM_DESTROY: PostQuitMessage( 0 ); return 0;// correct handlers://-------------------------case WM_CLOSE: DestroyWindow( hWnd ); PostQuitMessage( 0 ); return 0;case WM_DESTROY: return 0;
This is working fine so far, because under normal operating situations, I can't see my main application window being destroyed by any means other than in response to a WM_CLOSE message.
I couldn't figure out why this was a problem, though, because MessageBox will work even when there is no message loop. My only conclusions are that MessageBox will create a message loop if one is not present, or use the current existing one if there is. I don't know if this is the case, though I'm planning on testing on it this weekend.
Glad to see other people having and solving the same problems!
-- Succinct
/edit I like the idea of a FlushMessageQueue( HWND ) type function. Maybe I'll give that one a whirl.
[edited by - succinct on January 31, 2003 3:30:30 PM]