Detect external display being connected or removed under Windows 7

According to this article Windows sends the WM_DISPLAYCHANGE message when display resolution changes and also when a display is added or removed.

If you need to react to desktop size changes due to monitor addition or removal, you can do so in the handler of this message. The LPARAM gives you the new resolution of the display on which the window is located. Notice that this resolution will be scaled if you use anything else than 100% for system DPI scaling and your program is not DPI-aware.

Alternatively use the EnumDisplayMonitors function to get the display resolution for each connected monitor and the relative positions of the monitors in the virtual desktop. This functions uses the real device pixel values regardless of DPI scaling.

Leave a Comment