I'm trying to retrieve the no. of monitors being connected to a CPU.
Suppose, i've a system with 4 outputs being connected in Stretched mode and all 4 outputs together showing as a single screen. When i query the connected outputs count using any of the below methods i'm getting the response as "1".
"EnumDisplayDevicesA" method returns DISPLAY_DEVICE.StateFlag as DISPLAY_DEVICE_ATTACHED_TO_DESKTOP for only one display.
"EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&Count)" method also returns 1 output being connected
GetSystemMetrics(SM_CMONITORS) method also returns 1 output being connected
Is there any provision to identify the no. of monitors being connected regardless of the mode it is being configured? or
Is there a way to identify, How many monitors attached to the Primary screen when it is configured span/stretched mode?
when 3 displays are connected (for a QUAD output PC) in
Individual/Extended mode i'm getting the below output:
Device: \\.\DISPLAY1 is active. Flags: 5
Device: \\.\DISPLAY1 is primary. Flags: 5
Device: \\.\DISPLAY1 is attached to the desktop. Flags: 5
Device: \\.\DISPLAY2 is active. Flags: 1
Device: \\.\DISPLAY2 is attached to the desktop. Flags: 1
Device: \\.\DISPLAY3 is active. Flags: 1
Device: \\.\DISPLAY3 is attached to the desktop. Flags: 1
Device: \\.\DISPLAY4 is not attached. Flags: 0
Device: \\.\DISPLAYV1 is a mirroring driver device. Flags: 8
Device: \\.\DISPLAYV2 is a mirroring driver device. Flags: 8
4 monitors detected, 3 attached to the desktop, mirroring devices: 2
when the same 3 displays are connected (for a QUAD output PC) in
Span/Stretch/Duplicate mode i'm getting below output:
Device: \\.\DISPLAY1 is active. Flags: 5
Device: \\.\DISPLAY1 is primary. Flags: 5
Device: \\.\DISPLAY1 is attached to the desktop. Flags: 5
Device: \\.\DISPLAY2 is not attached. Flags: 0
Device: \\.\DISPLAY3 is not attached. Flags: 0
Device: \\.\DISPLAY4 is not attached. Flags: 0
Device: \\.\DISPLAYV1 is a mirroring driver device. Flags: 8
Device: \\.\DISPLAYV2 is a mirroring driver device. Flags: 8
4 monitors detected, 1 attached to the desktop, mirroring devices: 2
My code piece looking like below:
HMODULE user32 = GetModuleHandle ("User32.DLL");
typedef BOOL WINAPI tEnumDisplayDevices (void*, DWORD, DISPLAY_DEVICE*, DWORD);
tEnumDisplayDevices* fEnumDisplayDevices = (tEnumDisplayDevices*) GetProcAddress (user32, "EnumDisplayDevicesA");
if (fEnumDisplayDevices == NULL) return false;
int numMirrorDevices = 0, numMonitorsAttached = 0, numMonitorsTotal = 0;
DISPLAY_DEVICE dd; dd.cb = sizeof(dd);
for (DWORD dev=0; fEnumDisplayDevices (NULL, dev, &dd, 0); ++dev)
{
if (dd.StateFlags & DISPLAY_DEVICE_ACTIVE)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is active. Flags: " << dd.StateFlags);
}
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is primary. Flags: " << dd.StateFlags);
}
if (dd.StateFlags & DISPLAY_DEVICE_REMOVABLE)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is removable. Flags: " << dd.StateFlags);
}
if (dd.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is VGA. Flags: " << dd.StateFlags);
}
if (dd.StateFlags & DISPLAY_DEVICE_MODESPRUNED)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is more dsiplay modes. Flags: " << dd.StateFlags);
}
if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is a mirroring driver device. Flags: " << dd.StateFlags);
numMirrorDevices++;
continue;
}
if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is attached to the desktop. Flags: " << dd.StateFlags);
numMonitorsAttached++;
}
else
{
LOG_INFO (funcName << ": Device: " << dd.DeviceName << " is not attached. Flags: " << dd.StateFlags);
}
numMonitorsTotal++;
}
LOG_INFO (funcName << ": " << numMonitorsTotal << " monitors detected, " << numMonitorsAttached
<< " attached to the desktop, mirroring devices: " << numMirrorDevices);
Please guide me in identifying the right monitor count.
Thanks in advance.