Jump to content
  • Advertisement
Sign in to follow this  
_Phalanx_

Catching WM_ACTIVATE and handling it

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!