Why does EnumDisplayMonitors Still Return just Disconnected Monitor
I'm working om win32 Desktop application in CPP and I'm checking what happens if I try to fetch Display info with EnumDisplayMonitors when All displays are disconnected! Surprisingly it is giving display info of previously connected Display. Why is this so? Is it returning cached info?
Windows API - Win32
-
RLWA32 • 47,196 Reputation points
2025-02-11T08:33:43.86+00:00 If you use multiple monitors what does Device Manager show before disconnecting one of them and then after reconnecting it? Then try it again after scanning for hardware changes.
-
Harshithraj1871 • 1,581 Reputation points
2025-02-11T08:35:46.6166667+00:00 When we have multiple monitor the behaviours are fair, before disconnecting it will show 2 and after that it will show 1
-
RLWA32 • 47,196 Reputation points
2025-02-11T08:37:34.07+00:00 Is a manual scan for hardware changes needed to get the expected results?
-
Harshithraj1871 • 1,581 Reputation points
2025-02-11T08:40:45.1333333+00:00 Yes actually we want to do a manual scan before we bring up our window
-
RLWA32 • 47,196 Reputation points
2025-02-11T08:59:14.5166667+00:00 Maybe you could use WMI and the Win32_DesktopMonitor class to identify a disconnected monitor.
-
Castorix31 • 86,981 Reputation points
2025-02-11T09:12:33.2+00:00 Can't you use DISPLAY_DEVICE with DISPLAY_DEVICE_ACTIVE or DISPLAY_DEVICE_ATTACHED ?
-
Harshithraj1871 • 1,581 Reputation points
2025-02-11T09:22:13+00:00 @Castorix31 tried that with EnumDisplayDevices(), I have 1 Display connected, still it gave me 4 displays (1 active and 3 inactive).
Display Device 0: \\.\DISPLAY1 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. --------------------------------- Display Device 1: \\.\DISPLAY2 - Intel(R) UHD Graphics 770 Status: Active Primary Display: Yes Monitor 0: \\.\DISPLAY2\Monitor0 - Generic PnP Monitor Screen Resolution: 1920 x 1080 pixels Refresh Rate: 60 Hz --------------------------------- Display Device 2: \\.\DISPLAY3 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. --------------------------------- Display Device 3: \\.\DISPLAY4 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. ---------------------------------
And when i unplugged the my only monitor it still gave me 4 displays (1 active and 3 inactive).
Display Device 0: \\.\DISPLAY1 - Intel(R) UHD Graphics 770 Status: Active Primary Display: Yes Monitor 0: \\.\DISPLAY1\Monitor0 - Digital Flat Panel (640x480 60Hz) Screen Resolution: 1920 x 1080 pixels Refresh Rate: 60 Hz --------------------------------- Display Device 1: \\.\DISPLAY2 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. --------------------------------- Display Device 2: \\.\DISPLAY3 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. --------------------------------- Display Device 3: \\.\DISPLAY4 - Intel(R) UHD Graphics 770 Status: Inactive Primary Display: No Could not retrieve display settings. ---------------------------------
EDIT : after using DISPLAY_DEVICE_ATTACHED_TO_DESKTOP flag all the inactive enumeration can be skipped but when no display is connected - i will still get an Active display as in above output
-
RLWA32 • 47,196 Reputation points
2025-02-11T16:50:13.99+00:00 Yes actually we want to do a manual scan before we bring up our window
Some posts on the internet suggested using CM_Locate_DevNode with CM_LOCATE_DEVNODE_NORMAL and CM_Reenumerate_DevNode (requires Administrator privileges) to initiate a hardware scan.
-
Darran Rowe • 1,426 Reputation points
2025-02-11T19:40:31.53+00:00 Because that is an Intel(R) UHD Graphics adapter, is this a laptop? I'm wondering if there is something non obvious going on hardware wise, like extra hardware is being enabled when it detects an external display being plugged in.
-
Harshithraj1871 • 1,581 Reputation points
2025-02-12T06:16:25.6366667+00:00 @RLWA32 : Thanks I'm looking for some API which could run without Admin Mode
-
Harshithraj1871 • 1,581 Reputation points
2025-02-12T06:18:57.4933333+00:00 @Darran Rowe : No I'm not using Laptop. I'm using simple CPU-monitor Setup
-
Harshithraj1871 • 1,581 Reputation points
2025-02-12T09:09:17.0666667+00:00 Does windows keep any "virtual display" active even when all monitor is physically disconnected
-
Castorix31 • 86,981 Reputation points
2025-02-12T16:22:50.73+00:00 On my PC (1 monitor only), when I test both DISPLAY_DEVICE_ATTACHED && DISPLAY_DEVICE_ACTIVE, enumeration is skipped when I unplug it (Intel(R) HD Graphics and 247ELH Philips monitor)
Sign in to comment