My program isn't exiting...

Started by
4 comments, last by sirSolarius 20 years, 2 months ago
This is really strange... whenever I press ESC on my program, it breaks the while loop of my WinMain function, and continues to the last bracket of WinMain. If I''m in debug mode, after I exit I can shift-f5 to quit, but when compiled the program runs fine, when I press ESC it closes, but I noticed a huge performance hit. If I ctrl-alt-del, I see that my program is listed in the "Processes" section of Windows XP, and is running at like 97% CPU usage. What is going on?
Advertisement
I don''t get it. Is your program supposed to exit when you press ESC or shift+f5 or not? Normally it shouldn''t, unless you have coded it in.

quote:Original post by sirSolarius
If I ctrl-alt-del, I see that my program is listed in the "Processes" section of Windows XP, and is running at like 97% CPU usage.
That''s normal. All games is running at 97-99% CPU when it''s active because of the main loop.
Its never a good thing when your Process is still running AFTER you've told it to quit.

Sounds like a message pump error to me, make sure you PostQuitMessage() when you're ready for your program to stop.

Heres what mine tend to look like:

Message Pump:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){    switch(msg)    {	case WM_DESTROY:	case WM_CLOSE:		PostQuitMessage(0);		return 0;                break;	}	return(DefWindowProc(hWnd, msg, wParam, lParam));}



And heres my WinMain, starting from the beginning of the game loop.
  	// Loopity Loop Loop	MSG msg;	while(true)	{		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			if(msg.message == WM_QUIT)				break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}                // Rendering And Such Here	}	UnregisterClass("GroZZ3D", hInstance);	// Get The Hell Out Of Here...	return(msg.wParam);}


[edited by - GroZZleR on February 21, 2004 12:04:55 AM]
Grozzler''s got it, but thats only important if your useing the WS_SYSMENU style (its also in WS_OVERLAPPEDWINDOW)

anyways, show us your source solaris... then we can help, do you mean the x button? or the excape button on your keyboard? if its the x button, do what grozzler did, if its the escape on your keyboard, show source
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window							UINT	uMsg,			// Message For This Window							WPARAM	wParam,			// Additional Message Information							LPARAM	lParam)			// Additional Message Information{/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////WINDOWS MESSAGE HANDLING///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	switch (uMsg)									// Check For Windows Messages	{		case WM_ACTIVATE:							// Watch For Window Activate Message		{			if (!HIWORD(wParam))					// Check Minimization State			{				active=TRUE;						// Program Is Active			}			else			{				active=FALSE;						// Program Is No Longer Active			}			return 0;								// Return To The Message Loop		}		case WM_SYSCOMMAND:							// Intercept System Commands		{			switch (wParam)							// Check System Calls			{				case SC_SCREENSAVE:					// Screensaver Trying To Start?				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?				return 0;							// Prevent From Happening			}			break;									// Exit		}		case WM_CLOSE:								// Did We Receive A Close Message?		{			PostQuitMessage(0);						// Send A Quit Message			return 0;								// Jump Back		}		case WM_KEYDOWN:							// Is A Key Being Held Down?		{			keys[wParam] = TRUE;					// If So, Mark It As TRUE			return 0;								// Jump Back		}		case WM_KEYUP:								// Has A Key Been Released?		{			keys[wParam] = FALSE;					// If So, Mark It As FALSE			return 0;								// Jump Back		}		case WM_SIZE:								// Resize The OpenGL Window		{			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height			return 0;								// Jump Back		}	}	// Pass All Unhandled Messages To DefWindowProc	return DefWindowProc(hWnd,uMsg,wParam,lParam);}int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance					HINSTANCE	hPrevInstance,		// Previous Instance					LPSTR		lpCmdLine,			// Command Line Parameters					int			nCmdShow)			// Window Show State{.....while(!done)									// Loop That Runs While done=FALSE	{		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?		{			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?			{				done=TRUE;							// If So done=TRUE			}			else									// If Not, Deal With Window Messages			{				TranslateMessage(&msg);				// Translate The Message				DispatchMessage(&msg);				// Dispatch The Message			}}		else										// If There Are No Messages		{			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()			currentCam->Update();			if ((active && !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?			{				done=TRUE;							// ESC or DrawGLScene Signalled A Quit			}.....Key trapping stuff here.............The while(!done) loop closes at the next bracket:}///////////// PROGRAM DONE \\\\\\\\\\\\\\\\\\\\\\\\\\\//	delete currentCam;	KillGLWindow();									// Kill The Window	KillFont();	ReleaseCapture();	// Stop capturing mouse movements	ShowCursor(true);	// Show the cursor	return (msg.wParam);							// Exit The Program}

Sorry for the late reply but you gotta process WM_DESTROY as well, i really donmt think its guaranteed taht DefWindowProc() processes it right
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."

This topic is closed to new replies.

Advertisement