Memory is cleaned up by the scheduler on the OS when your process is done executing so Memory leaks when your process closes are fixed anyway. "PostQuitMessage(...)" does much more then just close the process you're looking at though so I would say go with it over "exit(...)".
WM_QUIT message is generated when the application calls the PostQuitMessage function. So calling PostQuitMessage() is this handler in redundant.
PostQuitMessage() is a typical response to the WM_DESTROY message.
Edit:
Computergeek01 wrote:
Clicking the close button should send a WM_QUIT message into the queue. Do you have something else handeling the WM_QUIT condition?
The close buttons send a WM_CLOSE message. This indicates a window or an application should terminate. Handling this message gives you the chance to intervene,canceling the close/saving data...
case WM_QUIT:
exit(0); // should I have this here?
It is interesting because (and I'm quoting from Microsoft info):
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.
Are you force sending the WM_QUIT message using the SendMessage function?
Im interested in what the Shutdown() function does.
codist, I was asking for your handler loop, not for your window procedure. The message handle loop is the thing that looks a little something like this:
Normally your window procedure never receives a WM_QUIT message, because the loop exits when the message reaches WM_QUIT, so DispatchMessage shouldn't be called. If your program doesn't exit after PostQuitMessage, this is the part that is most likely to be the cause.
while (!done) { //done is defined earlier
PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE);
if (msg.message == WM_QUIT) done = true; // I think this should quit it, but it doesn't seem to do
//anything unless I click the close button a few times.
render();
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Ah, I see. That's why. Do it like I did above (of course you can include your render code, though you should probably put that after dispatch message - actually it would be better to put render() into WM_PAINT, and call InvalidateRect on your window inside of a timer.)
@hanst99 - If I put render() in the handler loop, it goes very slow, even though I'm only drawing a cube. If I put it in the WM_PAINT message, and call InvalidateRect in a timer (with SetTimer()), it glitches up and uses a HUGE amount of memory, and computer usage.