Link to home
Start Free TrialLog in
Avatar of stitch2802
stitch2802

asked on

Monitor information using EnumDisplayDevices

Hi,

I'm trying to get the name of my monitor using the following code - it's giving me the name of the adapter instead:

bool MonitorInfo::Acquire()
{
    TCHAR msg[10000] = {0};
      DISPLAY_DEVICE dd;

      dd.cb = sizeof(dd);

      DWORD dev = 0; //device index

      int id = 1; //monitor number as used by Display Properties -> Settings

      while(EnumDisplayDevices(0, dev, &dd, 0))
      {
            if(!(dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
            {
                  
                  DISPLAY_DEVICE ddMon;
                  ZeroMemory(&ddMon, sizeof(ddMon));
                  ddMon.cb = sizeof(&ddMon);

                  DWORD devMon = 0;

                  
                  while(EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0))
                  {
                        if(ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE)

                              break;
                        devMon++;

                  }

                  if(!*ddMon.DeviceString)
                  {
                        EnumDisplayDevices(dd.DeviceName, 0, &ddMon, 0);
                        if(!*ddMon.DeviceString)
                        {
                              HRESULT hr = StringCchCopy(dd.DeviceString, sizeof(dd.DeviceString), TEXT("Default Monitor"));
                              if (FAILED(hr))
                              {
                                    return false;
                              }
                        }
                  }

                  //get information about the display position and the current display mode
                  DEVMODE dm;
                  ZeroMemory(&dm, sizeof(dm));
                  dm.dmSize = sizeof(dm);

                  if(EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
                  {
                        EnumDisplaySettingsEx(dd.DeviceName, ENUM_REGISTRY_SETTINGS, &dm, 0);
                  }

                  //format information about this monitor

                  MonitorInfoEx monInfoEx;

                  HRESULT hr = StringCchPrintf(monInfoEx.refreshRate, sizeof(monInfoEx.refreshRate), TEXT("%d"), dm.dmDisplayFrequency);
            if (FAILED(hr))
                  {
                        return false;
                  }
                  //device name
                  hr = StringCchCopy(monInfoEx.name, sizeof(monInfoEx.name), ddMon.DeviceString);
                  if (FAILED(hr))
                  {
                        return false;
                  }
                  id++;

                  monitors.push_back(monInfoEx);

            }
            dev++;
      }

      return true;
}

I've tried different combinations in the EnumDisplayDevices, but it either gives me the name of the video card or "Default Monitor". What I want is the name of the monitor as stated in the Device Manager.

Help, please?

TIA,
S/.
Avatar of joghurt
joghurt

EnumDisplayDevices should return the name of the display card (instead of the monitor). What about EnumDisplayMonitors and GetMonitorInfo function with MONITORINFOEX?
Avatar of stitch2802

ASKER

Could you give me an example, please?
Thanks, but that isn't what I'm looking for - the combination of EnumDisplayMonitors and GetMonitorInfo, along with MONITORINFOEX  gives me the following output: \\.\Display1

I'm trying to get the name of the monitor, for example: Samsung SyncMaster 753 DF.

TIA,
s/.
ASKER CERTIFIED SOLUTION
Avatar of rhanneken
rhanneken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rhanneken,

You're a genius! =)

Exactly what I was looking for, thanks!
s/.