4

我遇到了这篇文章,其中有人想使用 EnumDisplayDevices 找出他们的显示器的名称。

这正是我想要的,我尝试在 C++ 中做类似的事情,但对 EnumDisplayDevices 的第二次调用似乎从未返回任何内容,我只获得有关显卡的信息。

DISPLAY_DEVICE dd;
memset(&dd, 0, sizeof(DISPLAY_DEVICE));
dd.cb = sizeof(dd);
int i = 0;
while(EnumDisplayDevices(NULL, i, &dd, 0))
{
    Log(_T("Device Name: %s Device String: %s"), dd.DeviceName, dd.DeviceString);

    if(EnumDisplayDevices(dd.DeviceName, 0, &dd, 0))
    {
        Log(_T("Monitor Name: %s Monitor String: %s"), dd.DeviceName, dd.DeviceString);
    }

    i++;
} 

我得到的输出是

Device Name: \\.\DISPLAY1 Device String: NVIDIA GeForce 9300 GE
Device Name: \\.\DISPLAYV1 Device String: NetMeeting driver
Device Name: \\.\DISPLAYV2 Device String: RDPDD Chained DD

目标平台是 XP,我无法找到监视器名称的任何标准方法。有任何想法吗?

谢谢。

4

2 回答 2

4

After the first call to EnumDisplayDevices DispDev.DeviceString contains graphic card's name. After the second call DispDev.DeviceString contains monitor's name.

Also see this link for other ways to get this info

BOOL GetMonitorInfo(int nDeviceIndex, LPSTR lpszMonitorInfo) {
    BOOL bResult = TRUE;
    FARPROC EnumDisplayDevices;
    HINSTANCE  hInstUserLib;
    DISPLAY_DEVICE DispDev;
    char szDeviceName[32];

    hInstUserLib = LoadLibrary("User32.DLL");

    EnumDisplayDevices = (FARPROC)GetProcAddress(hInstUserLib,
                                                 "EnumDisplayDevicesA");
    if(!EnumDisplayDevices) {
        FreeLibrary(hInstUserLib);
        return FALSE;
    }

    ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
    DispDev.cb = sizeof(DISPLAY_DEVICE);

    // After first call to EnumDisplayDevices DispDev.DeviceString 
    //contains graphic card name
    if(EnumDisplayDevices(NULL, nDeviceIndex, &DispDev, 0)) {
        lstrcpy(szDeviceName, DispDev.DeviceName);

        // after second call DispDev.DeviceString contains monitor's name 
        EnumDisplayDevices(szDeviceName, 0, &DispDev, 0);

        lstrcpy(lpszMonitorInfo, DispDev.DeviceString);
    }
    else {
        bResult = FALSE;
    }

    FreeLibrary(hInstUserLib);

    return bResult;
}
于 2012-04-24T17:09:21.713 回答
0

我认为Win32_DesktopMonitor可能更适合您尝试做的事情。

于 2012-04-24T17:01:23.937 回答