4

I came across this post in which someone wants to find out the name of their monitor using 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++;
} 

The output I get is

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

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

Thanks.

Community
  • 1
  • 1
Bill Walton
  • 811
  • 1
  • 16
  • 31
  • FWIW, I have a post with a pointer to code that can extract this from the EDID block at http://stackoverflow.com/questions/10237937/looking-for-a-reliable-mapping-of-forms-screen-devicename-to-monitor-edid-info – holtavolt Apr 24 '12 at 17:05

2 Answers2

5

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;
}
user1810087
  • 5,146
  • 1
  • 41
  • 76
Flot2011
  • 4,601
  • 3
  • 44
  • 61
  • Hi Flot, Is it only possible to get names like "Plug and Play Monitor", because that's what I'm getting now. I wanted the monitors actual name, mine for instance is DELL P190S. – Bill Walton Apr 25 '12 at 08:11
  • Are you sure that the driver is an original Dell driver and not a common Plug&Play Windows driver? Because I am getting a real name of my monitor this way. – Flot2011 Apr 25 '12 at 11:58
  • In device manager it also just shows up as plug and play monitor, so I guess not. I thought the monitor name would come from the monitor's EDID, is this not the case and it just gets it from the driver? – Bill Walton Apr 25 '12 at 12:22
  • EDID does not expose a public API. You can either read from registry directly: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\\\Device Parameters` or use WMI and query the Win32_DesktopMonitor. – Flot2011 Apr 25 '12 at 14:55
  • Also see the link that I added in the answer – Flot2011 Apr 25 '12 at 15:08
  • Thanks Flot, reading the registry isn't an option as there may be many monitors in there which have been connected in the past, and I won't know which is the one that's currently connected. Win32_DesktopMonitor wasn't introduced until Vista. Doing this in XP is a real pain, I'll check out that other link though. Cheers. – Bill Walton Apr 25 '12 at 15:57
  • As a note re-using `DispDev` in this case didn't seem to work for me: https://stackoverflow.com/questions/9524309/enumdisplaydevices-function-not-working-for-me/9524900#comment132242091_9524900 See also https://stackoverflow.com/questions/10237937/looking-for-a-reliable-mapping-of-forms-screen-devicename-to-monitor-edid-info possibly related – rogerdpack Jan 05 '23 at 07:38
0

I think Win32_DesktopMonitor may be more suited to what you are trying to do.

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96