Click to See Complete Forum and Search --> : Trouble displaying a message box in message handler


matthias_k
July 27th, 2003, 01:00 PM
Hey there,

The weird problems strike back once again :)

This time I want to catch a WM_CLOSE message each time the user wants to exit the program, in order to display a message box asking the user if he really wants to exit. If he clicks YES, a WM_QUIT message is sent. If NO, I return from the message handler.

The problem is... the message box shows up, but it takes waaay longer than it should. If I hit escape to tell the app I want to exit, it takes like 5 seconds until the message box finally appears. During this time the app seems to freez, I can't even maximize/minimize it or do some other default operation.

Here's the code of my window's message handler:


LRESULT CApplication::WindowProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
switch( nMsg )
{
case WM_COMMAND:

break;

case WM_KEYDOWN:

switch( LOWORD( wParam ) )
{
case VK_ESCAPE:
PostMessage( hWnd, WM_CLOSE, wParam, lParam );
break;

default:
break;
}

break;

case WM_PAINT:

break;

case WM_CLOSE:

if( MessageBox( hWnd, "Really want to quit?", "Exit program", MB_YESNO|MB_ICONQUESTION ) == IDYES )
PostQuitMessage( 0 );

break;

default:
return DefWindowProc( hWnd, nMsg, wParam, lParam );
}

return 0L;
}

This method is called from the global CALLBACK message handler.

Any ideas?

SilentJackqh
July 27th, 2003, 01:33 PM
what if the u delete the WM_PAINT if u don't used it.
I have the same problem like this in past, but when I delete WM_PAINT that I don't used, it works fine after that.

Paul McKenzie
July 27th, 2003, 01:49 PM
Originally posted by matthias_k
Hey there,
The problem is... the message box shows up, but it takes waaay longer than it should. If I hit escape to tell the app I want to exit, it takes like 5 seconds until the message box finally appears. During this time the app seems to freez, I can't even maximize/minimize it or do some other default operation.


a)Comment out the code that is not relevant (WM_PAINT, WM_CHAR) and see if the problem goes away.

b) Start out with a skeleton application and see if the problem exists in that version. If it doesn't occur, then the problem is probablye somewhere in the code you didn't post.

c) Use a code profiler to determine what function causes the slow processing.

Regards,

Paul McKenzie

matthias_k
July 27th, 2003, 02:05 PM
Ah, thanks a lot. I deleted the blocks I don't use and now it works.

By the way:
Where do I get a profiler to analyze my code?

Paul McKenzie
July 27th, 2003, 02:10 PM
Originally posted by matthias_k
Ah, thanks a lot. I deleted the blocks I don't use and now it works.

By the way:
Where do I get a profiler to analyze my code? http://www.glowcode.com has a profiler (they have a 30-day trial of their product).

Regards,

Paul McKenzie

filthy_mcnasty
July 28th, 2003, 01:04 AM
to elaborate..... if you handle the WM_PAINT message yourself you need to at least call BeginPaint and EndPaint or return the DefWindowProc for it. in your case you returned 0

matthias_k
July 28th, 2003, 02:57 AM
Thanks for your answers, you helped a lot.