Can a message-only window receive WM_QUERYENDSESSION?
winapi, windows
Solution
MSDN gives a decent definition of a "message-only window":
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.
Relevant detail highlighted.
You use them to take advantage of the message dispatch mechanism in your own code. Most typically to get a worker thread to talk to the UI thread in a thread-safe way. A message loop is the universal solution to the producer-consumer problem. Apartment marshaling in COM is implemented with a message-only window for example. Clearly such a window should be hidden and only get the messages that are defined by the app.
Don't use HWND_MESSAGE as hWndParent when calling CreateWindowEx.
Problem
In the debug version of the program, I create a visible window, and the `WM_QUERYENDSESSION` message is received by its `WNDPROC`. In the release version, the window is supposed to be message-only, so I specify `HWND_MESSAGE` as the `hWndParent` when calling `CreateWindowEx()`. Unfortunately, I then don't receive the `WM_QUERYENDSESSION` message anymore. Is `WM_QUERYENDSESSION` one of those broadcast messages mentioned here? A message-only window [...] does not receive broadcast messages.