The problem is that when I close my application using the cross in the upper right corner or by hitting alt+f4 the application closes down properly and the process exits.
However when I close the application from the taskbar either by hitting the cross on the window thumbnail or by right clicking and selecting close, then the window gets destroyed but the process never exits.
Here is my code that handles these parts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | LRESULT CALLBACK WindowProc(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam) { LRESULT Result; switch(Message) { ... case WM_CLOSE: { DestroyWindow(Window); // NOTE(pete): (from MSDN) If an application processes this // message, it should return zero. Result = 0; } break; case WM_DESTROY: { // TODO(pete): There is a super annoying bug where the app wont // quit properly when closing from the taskbar? The window gets // destroyed but no WM_QUIT message seems to be posted/recieved? PostQuitMessage(0); // NOTE(pete): (from MSDN) If an application processes this // message, it should return zero. Result = 0; } break; ... default: { Result = DefWindowProc(Window, Message, WParam, LParam); } break; } return(Result); } |
And here is the message loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | if(Window) { ShowWindow(Window, CommandShow); UpdateWindow(Window); BOOL Result; MSG Message; while((Result = GetMessage(&Message, Window, 0, 0)) != 0) { if(Result == -1) { // TODO(pete): An unknown error occured logging/message? OutputDebugStringA("Are we hitting this?\n"); break; } else { TranslateMessage(&Message); DispatchMessage(&Message); } } } |
If I pause the in the debug window after the window has closed, the process is halted on the
1 | while((Result = GetMessage(&Message, Window, 0, 0)) != 0) |
Is there some other thing I need to handle to be able to close the window properly from the taskbar?
Edit: I can also verify that the application recieves and handles the WM_CLOSE and WM_DESTROY messages. However I am never hitting the point where OutputDebugStringA("Are we hitting this?\n"); gets called in the message loop.
// Pete