#### Archived

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

# Application not quitting

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a problem with my Win32 App not quitting. I click the X in the top corner and the window goes away but the system is now using 100% cpu power towards my app which task manager says is still up and it boggs down my system horribly. Here's my message handling loop:

if(game->BeginGame(g_hwnd))
{
while(true)
{

if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
//game->MainGame();

}

}

}else{
//game->EndGame();

}

My WndProc just handles the WM_DESTROY message by calling PostQuitMessage(0); Also, when I add Direct 3D Into the mix whenever my application loses focus it REALLY bogs my system down. Any one know whats going on? PS: the If statement just checks if initialization was a success and the commented out lines I commented out to see if they were causing the problem but they werent [edited by - perfectly_dark on August 31, 2002 12:14:06 AM]

##### Share on other sites
Perhaps the problem is caused by no handling of the WM_CLOSE message? Just put SendMessage(hWnd,WM_DESTROY,0,0) there.

"If people are good only because they fear punishment and hope for reward, then we are a sorry lot indeed." - Albert Einstein

##### Share on other sites
You are sending the quit message but not processing it. Do something like this:

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

##### Share on other sites
Hrm...the problem seems to be as simple as the fact that even if a quit message a recieved, nothing sends the application out of the infinite while loop....there is no break statement there or a check to see if the message the PeekMessage received as a WM_QUIT message.

##### Share on other sites
Yah, it quits now, I needed that if and break statement, can''t see how I missed it cause I tried that before. Thx for the help. I still have that problem with terrible preformance while the window is out of focus, anyone know how to fix that?

##### Share on other sites
Don't worry about that, it will go away when you start rendering polys

[edited by - R4V3R on September 1, 2002 9:53:35 AM]

##### Share on other sites
I think it would be a better idea to write this:

game->MainGame();

outside the else block. In your situation, I think that if you have several messages waiting in the message queue, you MainGame code will execute only when those messages have been processed. If you put that function call outside the else block, you can be sure that MainGame() will be called every iteration in the while loop.

##### Share on other sites
Create a global variable that signals the activeness of your application.

BOOL g_bActive;

Then in the WM_APPACTIVATE mark the variable depending on the focus of your program.

Have your main loop check if the application is active and if so, then and ONLY then you process the rest of the stuff. Otherwise you idle until your application is back in focus.