如何检索拉伸/跨度模式的连接监视器?

时间:2014-09-01 11:23:04

标签: c++ windows

我试图找回号码。监视器连接到CPU。

假设我有一个系统,其中4个输出连接在拉伸模式,所有4个输出一起显示为单个屏幕。当我使用以下任何一种方法查询连接的输出计数时,我得到响应为" 1"。

  1. " EnumDisplayDevicesA"方法仅将DISPLAY_DEVICE.StateFlag作为DISPLAY_DEVICE_ATTACHED_TO_DESKTOP返回给一个显示器。

  2. " EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,(LPARAM)& Count)"方法还返回1个连接的输出

  3. GetSystemMetrics(SM_CMONITORS)方法也返回1个连接输出

  4. 是否有任何规定来确定号码。监视器是否连接,无论其连接的模式如何?

    最终,我需要知道的是,有多少监视器连接到系统,无论其配置模式如何。

    当在个人/扩展模式下连接3个显示器(对于QUAD输出PC)时,我得到以下输出:

    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
    

    当在跨度/拉伸/重复模式下连接相同的3个显示器(对于QUAD输出PC)时,我会低于输出:

    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
    

    我的代码片如下所示:

    // 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);
    

    请指导我确定合适的显示器数量。

0 个答案:

没有答案