Sign in to follow this  

empty win32 program somehow eating up processor! argh!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I just wrote a very simple windows program that does nothing but create a window... and it is apparently using 50% of my CPU. this is crazy - what's going on here? help! the entire source code is below: #include <windows.h> HINSTANCE hinst; HWND hwndMain; LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { case WM_CREATE: return 0; case WM_PAINT: return 0; case WM_KEYDOWN: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, iMsg, wParam, lParam); } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { MSG msg; BOOL bRet; WNDCLASS wc; UNREFERENCED_PARAMETER(lpszCmdLine); // Register the window class for the main window. if (!hPrevInstance) { wc.style = 0; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION); wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = "MainMenu"; wc.lpszClassName = "MainWndClass"; if (!RegisterClass(&wc)) return FALSE; } hinst = hInstance; // save instance handle // Create the main window. hwndMain = CreateWindow("MainWndClass", "Sample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND) NULL, (HMENU) NULL, hinst, (LPVOID) NULL); // If the main window cannot be created, terminate // the application. if (!hwndMain) return FALSE; // Show the window and paint its contents. ShowWindow(hwndMain, nCmdShow); UpdateWindow(hwndMain); // Start the message loop. while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } } // Return the exit code to the system. return msg.wParam; }

Share this post


Link to post
Share on other sites
I haven't tried to run this code but here are few question that when answered could help you:

Does this happen when you debug as well?
If so, is there a specific point at which the resources get eaten up or is during the whole run?
Does that happen when you run this as standalone program?

Once you have these figured, try to see what differences these environments introduce and what impact might they have on your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by wannabe H4x0r
/\ no read above, it was just me being stupid. if you don't invalidate the rect explicitly windows will just constantly try to keep trying to redraw your window

thanks tho
Exactly what I was going to say, and it only took me 5 seconds to spot too.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this