I'm trying to retrieve the display mode it is being configured in the OS.
Suppose, when a system has graphic card (any vendor) which supports connecting multi-displays. I'm able query the no. of monitors being connected when display settings configured to extended mode. But, for Span/Duplicate modes, always returns only 1 monitor being connected.
Is there a way to identify
- no. of monitors being connected regardless of the mode it is being configured? or
- no. of monitors being attached to the primary display for span/duplicate mode? or
- what type of mode the display is being configured?
I'm using the below code to identify the display count:
// I need to get the address of a few multi-monitor functions
//
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 fResult;
fResult = GetSystemMetrics(SM_CMONITORS);*/
// count the number of monitors attached to the system
//
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);
and the output for this code as follows:
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
Please let me know if you need any further information.
Thanks in advance.