CPU going to 100% upon exiting

This is a discussion on CPU going to 100% upon exiting within the Windows Programming forums, part of the Platform Specific Boards category; Ok, I'm stumped on this one, maybe someone else can catch whatever little error I have in this program. Basically ...

CPU going to 100% upon exiting

Ok, I'm stumped on this one, maybe someone else can catch whatever little error I have in this program. Basically whats happening is the program works fine while running, but the instant it closes my CPU goes to 100% and I have to go to task manager and end the process manually. I've commented everything out but the essentials yet it is still doing it, any help? Heres the code:

GetMessage returns -1 if it fails. Typically, GetMessage will fail because of an invalid argument, such as a window handle that no longer points to a window.

You should use NULL for the hwnd parameter of GetMessage. This lets it return messages for all windows belonging to the thread as well as thread messages. See the documentation for an example of error handling for the GetMessage function.

D'oh, thanks, you're absolutely right. I was having problems with combo boxes showing and I saw a post from a little while ago where someone else had it changed to hwnd so I tried it and forgot to change it back. Thanks for the help!

Because you're using hwnd in the call to GetMessage(), the function is failing before it has a chance to pull out the WM_QUIT and return 0.

When GetMessage() fails, due to an invalid HWND for example, it will return -1, not 0. So you keep on loop'n.

The quick fix is to use NULL for the HWND in the call to GetMessage(), that way there's no invalid HWND to fail on. The correct fix is to implement a message loop like the example in the GetMessage() documentation.