• Advertisement

Archived

This topic is now archived and is closed to further replies.

Why wont my MessageBox show?

This topic is 5505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m writing a DirectX app. When an error occurs an exception is thrown and my ''catch {}'' handler should display a MessageBox. However, all I hear is the sound associated with the MessageBox style and the program just skips over the function. Any solutions?

Share this post


Link to post
Share on other sites
Advertisement
Hm. That didn''t work. Any other ideas?
I know this can also happen if I destroy a window just before I call MessageBox. Its happened before, but this time I''m sure I haven''t destroyed anything yet, since the window is still visible on the desktop.

Share this post


Link to post
Share on other sites
Put your window handle (hWnd) into for the HWND parameter...

[edit]note that this may not work in debug mode... but try it [/edit]

[edited by - Bullmax on January 30, 2003 11:23:26 PM]

Share this post


Link to post
Share on other sites
That didn''t work either. Has anybody else encountered a problem with MessageBox(es) not showing (and any solutions/suggestions?)

Share this post


Link to post
Share on other sites
I think the function you''re looking for is FlipToGdiSurface. I seem to recall an SDK sample dealing with this (and dialog boxes) but, for the life of me, can''t remember which one, (and I''m too pressed for time to do a Find in Files. )

Hope that helps,
-scott

Share this post


Link to post
Share on other sites
Maybe including MB_TOPMOST in the message box''s parameters will help.

------------------------------------------------------------
I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites
No, that didn''t help. Been trying for quite awhile now. Have no idea what is wrong. *confused*

Share this post


Link to post
Share on other sites
Still checking what''s wrong. (Pathetic, ain''t it?) Found that the MessageBox function is always returning the value IDOK. It''s as if the OK button is being pressed by default. As an alternative, I''ve tried to create a modal dialog using the DialogBox function. Surprise, it doesn''t work either, not displaying the dialog, and returning the value 1 as well.

Share this post


Link to post
Share on other sites
I always use this macro for sowing a messagebox. I''ve never had any problems with it:

#define MSGBOX(body) MessageBox(NULL,body,"MESSAGE",MB_OK);

you call it with MSGBOX("TEXT");

______________________________
"A computer is meant to be a big calculator, not a storage device"
Struct.m33p.net

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 queue

MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}


Hope this helps anyone who might encounter/have encounted this problem.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement