josh3736
josh3736

Reputation: 144972

Not receiving WM_DISPLAYCHANGE

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

Answers (2)

Grey
Grey

Reputation: 23

Maybe you should satisfy following two conditions if you want receive WM_DISPLAYCHANGE msg from Windows:

  1. Top-level Window, you shoule create a window that hwndParent parameter is NULL or HWND_DESKTOP
  2. Message Loop, just like this:
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

Remy Lebeau
Remy Lebeau

Reputation: 596833

This might have something to do with it:

Message-only windows

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

Related Questions