My program isn't exiting...
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?
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 sirSolariusThat''s normal. All games is running at 97-99% CPU when it''s active because of the main loop.
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.
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:
And heres my WinMain, starting from the beginning of the game loop.
[edited by - GroZZleR on February 21, 2004 12:04:55 AM]
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement