Ah, so I tested again by supplying the Window parameter
while((Result = GetMessage(&Message, Window, 0, 0)) != 0) and it turns out that it never handles the WM_QUIT at all (poor debugging by my part). When closing the Window using alt+f4 it exits with
Result = -1, and the message is a WM_NULL message.
| + Message,wm {msg=WM_NULL wp=0x0000000000000000 lp=0x0000000000000000} tagMSG
- Message {msg=0x00000000 wp=0x0000000000000000 lp=0x0000000000000000} tagMSG
+ hwnd 0x0000000000000000 <NULL> HWND__ *
message 0 unsigned int
wParam 0 unsigned __int64
lParam 0 __int64
time 0 unsigned long
+ pt {x=0 y=0} tagPOINT
Result -1 int
|
The error is
| $err,hr ERROR_INVALID_WINDOW_HANDLE : Invalid window handle (handle). unsigned int
|
So somehow the Window gets destroyed such that the handle gets invalid if I use alt+f4 and not when using taskbar.
In both cases the DestroyWindow call gets executed and in both cases the Window handle in the WinProc is the same as the Window created in WinMain.
WinMain
| + Window 0x00000000000a0d48 {unused=??? } HWND__ *
|
WinProc
| + Window 0x00000000000a0d48 {unused=??? } HWND__ *
|
Also if I read the remarks on msdn about WM_QUIT more closely it says this.
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.
Most of this is from me not reading carefully enough so I am thankfull for your patience :)
What I have gathered from this is that in the main window message loop you probably want to pass NULL as a window handle and then pay more attention to what window handle gets passed to the WinProc if I have a bunch of buttons etc that you want to handle outside of their specific WinProcs somehow. Or I have multiple message loops but this requires additional threads?
Edit:
From MSDN about hWnd parameter in GetMessage().
If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd value is NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or PostThreadMessage.
So if you wanted to handle this in a seperate loop you would have one for the thread and pass -1 as hWnd. Guess it's always in the details.