使用EnumDisplayDevices获取显示器的名称 [英] Getting the monitor's name with EnumDisplayDevices

查看:3214
本文介绍了使用EnumDisplayDevices获取显示器的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个的帖子中,有人想使用EnumDisplayDevices找出他们的显示器的名称。

I came across this post in which someone wants to find out the name of their monitor using EnumDisplayDevices.

这正是我想要的,我试图在C ++中做类似的事情,但第二次调用EnumDisplayDevices似乎不会返回任何东西,我只能获得有关图形的信息

This is exactly what I want, and I tried to do something similar in C++ but the second call to EnumDisplayDevices never seems to return anything, I only get information about the graphics card.

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,我不能以任何标准方式找出监视器名称。任何想法?

The target platform is XP, and I can't any standard way of finding out the monitor name. Any ideas?

感谢。

推荐答案

第一次调用到EnumDisplayDevices DispDev.DeviceString包含图形卡名称
第二次调用之后,DispDev.DeviceString包含监视器名称

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

=http://thetweaker.wordpress.com/2011/11/13/reading-monitor-physical-dimensions-or-getting-the-edid-the-right-way/ =nofollow> link a>获取此信息的其他方法

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;
}

这篇关于使用EnumDisplayDevices获取显示器的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆