Why wont my MessageBox show?

Started by
11 comments, last by atjs 21 years, 2 months ago
No. That's not it.


  DWORD y = GetLastError();int x = MessageBox(0, GENERIC_ERROR, APP_TITLE, MB_ICONEXCLAMATION);y = GetLastError();  


On the first GetLastError(), it returns 0, meaning no error. After executing MessageBox(), GetLastError() returns 2. After checking, I've found it means 'The system cannot find the file specified' . File not found?! In a MessageBox? What is going on?

[edited by - atjs on January 31, 2003 4:59:18 AM]
Advertisement
Finally fixed it!!! What happened was during program shutdown, the app left the message pump loop. This resulted in messages arriving after the WM_QUIT message not being processed. This affected the main program window and in turn also affected the MessageBox function. The solution was to clear all remaining messages in the message queue before calling MessageBox.


  // clear all remaining messages in queueMSG msg;while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){	TranslateMessage(&msg);	DispatchMessage(&msg);}  


Hope this helps anyone who might encounter/have encounted this problem.
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]
-- Succinct(Don't listen to me)

This topic is closed to new replies.

Advertisement