I'm curious, what is the Win32 notification that is broadcast when the number of monitors in the system changes? I thought it was WM_DISPLAYCHANGE but I was wrong.
Asked
Active
Viewed 3,449 times
1 Answers
14
This is quite easy to check with Microsoft Spy++
. In my case I checked on Windows 7 x64 with two monitors connected and switching the second monitor off and on again.
When removing a monitor you will see a WM_DISPLAYCHANGE
, but not when adding a monitor.
You will see a WM_DEVICECHANGE
with DBT_DEVNODES_CHANGED
(after RegisterDeviceNotification).
You will see WM_SETTINGCHANGE
for SPI_SETWORKAREA
and SPI_ICONVERTICALSPACING
.
And you will see registered messages "UxdDisplayChangeMessage" and "HotplugDetected" (second one only when adding monitor). You can use RegisterWindowMessage to get the identifier for these messages.

Werner Henze
- 16,404
- 12
- 44
- 69
-
An edge case I can think of is adding a monitor that is mirroring the display instead of extending it. Would it still get `SPI_SETWORKAREA` if the work area isn't changing? – indiv Nov 17 '15 at 16:43
-
@indiv I don't know. The results are from tests I just made. You can easily check that yourself with Spy++. If I should guess, I'ld expect to see UxdDisplayChangeMessage, HotplugDetected and WM_DEVICECHANGE, but not WM_DISPLAYCHANGE and WM_SETTINGCHANGE. – Werner Henze Nov 17 '15 at 16:46
-
1@WernerHenze: Thanks. `WM_SETTINGCHANGE` with `wParam == SPI_SETWORKAREA` seems to do the trick for adding and removing monitors on all OS's down to XP. I'm not sure about the rest of your proposed solutions though. If Spy++ shows something, it doesn't mean that it's a documented approach. – c00000fd Nov 18 '15 at 09:13
-
Wasn't able to get any of these messages to be shown. :( – Adrian Jul 03 '18 at 15:35
-
1@Adrian I suggest opening a new question where you provide your code and reference this question here. – Werner Henze Jul 04 '18 at 07:37
-
1"removing monitor you see WM_DISPLAYCHANGE, but not when adding a monitor" -------> This information is NOT TRUE. At least not on Win7! I tried it. Disconnecting the monitor sends the signal. Connecting the monitor back, sends the signal again. Can anyone else confirm my experiment? Also, the documentation does not backup your statement: https://learn.microsoft.com/en-us/windows/win32/gdi/wm-displaychange – Gabriel Jul 15 '20 at 15:51