Getting a monitor name using EnumDisplayDevices

I came across this 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 video 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 cannot find a standard way to find out the name of the monitor. Any ideas?

Thank.

+3
source share
2 answers

EnumDisplayDevices DispDev.DeviceString . DispDev.DeviceString .

.

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 name 
        EnumDisplayDevices(szDeviceName, 0, &DispDev, 0);

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

    FreeLibrary(hInstUserLib);

    return bResult;
}
+4
0

All Articles