Windows not dispatching messages propably

Started by
7 comments, last by JoCCo 20 years, 3 months ago
Hello, I''m developing a little game engine just for fun, but I''m having problems with my message loop... I''ll give you some code... m_bActive is true when the program starts, the only place that changes it is this (it''s inside the message proc):

			case WM_ACTIVATEAPP:
				m_bActive = wParam;
				break;

	while (msg.message != WM_QUIT)
	{
		if ( PeekMessage( &msg,NULL,0,0,PM_NOREMOVE ) )
		{
			if ( GetMessage(&msg, NULL, 0, 0) < 0 )
				return msg.wParam;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
                }
		else
		{
			if (m_bActive)
			{
			        Update();
			}
			else
				WaitMessage();
		}
	}

My problem simply is that the app works fine until you minimize the application, then windows dosen''t leave the WaitMessage loop correctly (if I start to pause the program using the debugger it sometimes comes out of the loop and the application starts to behave correctly)... I''ve tried with Sleep instead of WaitMessage(with lots of diffrent vaules, in the range from 100 - 1000) and nothing helps, I get the same error anyway...
Advertisement
Personally, I have a problem with your message loop. What is all that stuff? Let me show you mine (IIRC, not at my code):
while( true ) {    while( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) {        if( msg.message == WM_QUIT ) break;        TranslateMessage( &msg );        DispatchMessage( &msg );    }    else if( bActive ) {        Kernel::GetInstance().Run();    }}

And I remember I used to check bActive with the WM_ACTIVATE message; look up the parameters, I never memorized them correctly.
I tend to foreshorten the windows message loop even more:

while( GetMessage( &msg, NULL, 0, 0 ) ) {

TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;

}

Although, if this is a windows app, with menus, you might want to do this

while( GetMessage( &msg, NULL, 0, 0 ) ) {

if( !TranslateAccelerator( hWnd, hAccel ) ) {

TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

return msg.wParam;
}

If you want to handle menus with accelerator keys.
I tend to foreshorten the windows message loop even more:

while( GetMessage( &msg, NULL, 0, 0 ) ) {

TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;

}

Although, if this is a windows app, with menus, you might want to do this

while( GetMessage( &msg, NULL, 0, 0 ) ) {

if( !TranslateAccelerator( hWnd, hAccel ) ) {

TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

return msg.wParam;
}

If you want to handle menus with accelerator keys.
OKay, thx for the posts, I''ll clarify what I mean..

First of, I know of TranslateAccelerators, but it''s for a non menu win32 app so it''s not a problem...

Second, my problem is that I want the app to stop running when it''s minimised, therefor the use of WaitMessage( or Sleep).

But I have the same problem even without it, the application dosen''t forward my messages correctly because I never get out of the Sleep( or WaitMessage) loop...
Is there a message that occurs when it stops sleeping that you aren''t catching?

I don''t have a Win32 API reference handy or I''d try to look it up for you.
It throws WM_ACTIVEAPP messages, and I catch those and change my bool so that part works great, the problem is that it never returns from the WaitMessage function( so that I can process that fact that my application now is able to run).
I just use WM_ACTIVATE and never really found out what the difference is between the two. Maybe you have to be checking only the low word part also. Not sure. Here''s mine:

      case WM_ACTIVATE: // twf - what''s the diff with WM_ACTIVATEAPP?         if (LOWORD(wParam) == WA_INACTIVE)         {            gf_bActive = false;         }         else         {            gf_bActive = true;         }         msgResult = 0;         break;


Tadd
- WarbleWare
Tadd- WarbleWare
Thx I seem to have gotten it to work now...

my problem as it seems right now it that the window dosen''t necassarily repaint itself when it is Maximized and that causes it to look like the message dosen''t get rerouted correctly...

( If I try to debug the app I figured out that I keep taking the focus away from the window thus not giving it time to tell me that the message is handled correctly )...

Anyway, so the problem now seems to have to do with repainting the window when it''s maximized, something I think I can handle..

Thanks for the help everyone...

This topic is closed to new replies.

Advertisement