Reputation: 144972
I've created a simple window to receive messages:
CreateWindow(L"MyClass", 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, 0);
I'm intrested in WM_DISPLAYCHANGE
to detect when monitors are plugged in/removed, but I never receive the message. My window receives other messages, but never WM_DISPLAYCHANGE
. Why?
Upvotes: 3
Views: 2554
Reputation: 23
Maybe you should satisfy following two conditions if you want receive WM_DISPLAYCHANGE msg from Windows:
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
I have tested that disable message loop, e.g. use while(1) {}
before message loop, in this condition i can't receive WM_DISPLAYCHANGE when resolution changed.
Upvotes: 0
Reputation: 596833
This might have something to do with it:
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.
Upvotes: 8