Application not quitting

Started by
7 comments, last by perfectly_dark 21 years, 7 months ago
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]
Advertisement
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
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);
}
}
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.
"Ogun's Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
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?
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]
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.
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.

-G|aD-
Ok, I''m now checking if the application is active and it seems to be working. Task Manager still says its using like 90% of CPU resources but I think thats because no other app is doing anything. Then again, neither is my app, how can I get it to let go of the resources. When I launch another app they basically split the resources but when the other app is running its not using much resources. Is there an easy way to do this or is this like advanced stuff. Thanks for all the help btw.

This topic is closed to new replies.

Advertisement