Sign in to follow this  
_Phalanx_

Catching WM_ACTIVATE and handling it

Recommended Posts

hey, i want to make my game catch WM_ACTIVAE and pause my game when i do catch it. If anyone has a code snippet they can post showing what they did to make your window stop taking cpu cycles when it is deactivated. i notice windows does a nice job of pausing while i move or resize the window. It pauses the window clock and as far as i can see basically does nothing untill you are done your moving or resizing. I was wondering if there was some way i could tell windows to pause it like that when it isnt being used. This allows me to have even less unnecesary cpu time used and it makes it easier for me to code :D

Share this post


Link to post
Share on other sites
So you didn't manage to dig it up from MSDN?
Well there you go:

// the signature could be wrong - from top of my head, but it's something like that :)
LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
// .... your other messages
case WM_ACTIVATE:
if (wParam == WA_INACTIVE) {
WaitMessage();
}
return 0;
}
return DefWndProc(hwnd, uMsg, wParam, lParam);
}


If the above deosn't work, try setting a flag instead and call WaitMessage() in your game loop if the flag is set.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i would suggest not using darookie's suggestion of calling WaitMessage in response to window de-activation. i would suggest using the flag instead, but have it call GetMessage:


if( m_active )
haveMsg = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
else
haveMsg = GetMessage (&msg, NULL, 0, 0);



the reason why i suggest doing this is because WaitMessage will not return even if there are msgs waiting in the thread's msg queue if your app had just called PeekMessage or GetMessage, which may very well be the case with a game since most of the processing is done in your gaming loop and not interacting with the OS API.

Share this post


Link to post
Share on other sites
Hey, i think ill try dookies method firs, (because that is the one i understand more). I am just wondering exactly how that waitmessage function works and if it allows other things to go on while it is waiting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this