Jump to content
  • Advertisement

Archived

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

Windows not dispatching messages propably

This topic is 5244 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

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...

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!