Archived

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

olle55

How do i pause my game?

Recommended Posts

olle55    122
Hello! I am trying to make my game pause while its not in focus in windowed mode, or if the user has alt+tabbed in fullscreen. How would i go about doing this? I think someone said that windows sends a message when the application gets focused and unfocused? Is that the way to do it? In that case, what are the messages? If anyone has any example code of this it would be much appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
olle55    122
I looked it up on msdn and it is correct, but i cant get it to work, the game continues to run if i unfocus the window.

This is the code i wrote:


  
switch (msg)
{
case WM_ACTIVATEAPP:
{
if (wParam)
{
running = true;
}
else
{
running = false;
}
}break;

default:break;
}


My main game loop, as you can see Game_main() should only be run if running is "true", which it fails to be when i unfocus the window.



  
// enter main event loop

while(TRUE)
{
// test if theres a message in queue, if so get it

if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;

// translate ant accelerator keys

TranslateMessage(&msg);

// send the message to the window proc

DispatchMessage(&msg);
}
if(running == true)
Game_Main();
}


Thanks in advance!

Share this post


Link to post
Share on other sites
olle55    122
You see i check if running is true right above Game_Main();
The main loop is only exited if it recives a WM_QUIT message.

  
if(msg.message == WM_QUIT)
break;

Share this post


Link to post
Share on other sites
ShawnO    145
Take a look at the file d3dapp.cpp from the sample framework that comes with the DirectX SDK. It handles the WM_SIZE message and checks for SIZE_MAXHIDE or SIZE_MINIMIZED to determine if the application is active.
Also be sure to take a look at the main message loop in the Run() method. Notice that it calls PeekMessage() only if the application is active, otherwise it calls GetMessage() to keep CPU usage low when the application is inactive.


[edited by - ShawnO on September 30, 2002 1:37:29 PM]

Share this post


Link to post
Share on other sites
IFooBar    906
I just handle two messages that takes care of everything. WM_ACTIVATE, and the one Shawn0 mentions..WM_SIZE.

WM_ACTIVATE with tell u when the app is active or not, and WM_SIZE lets u know when its minimized or restored or maximized. Then to check for alt+tab, u might as well use TestCooperativeLevel() a directX function. that will check to see if the device is lost. if the function returns a success that means the user hasnt lost teh device. (when the user alt+tabs the device is lost) If the function returns D3DERR_DEVICENOTRESET (i think its that) that means the user ahs alt+tabed (or maybe something else has happened) but it definetly means u have to stop rendering ur game a restore the device. I check TestCooperativeLevel every frame and only proceed with rendering if the the function succeeds.




"Your friendly proggy.....Al "
[Triple Buffer]|[SCRIPTaGAME]|[My Old Site]

Share this post


Link to post
Share on other sites