Solved

Monitor information using EnumDisplayDevices

Posted on 2004-04-16
5
2,578 Views
Last Modified: 2013-12-03
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/.
0
Comment
Question by:stitch2802
  • 3
5 Comments
 
LVL 6

Expert Comment

by:joghurt
ID: 10848923
EnumDisplayDevices should return the name of the display card (instead of the monitor). What about EnumDisplayMonitors and GetMonitorInfo function with MONITORINFOEX?
0
 

Author Comment

by:stitch2802
ID: 10851694
Could you give me an example, please?
0
 

Author Comment

by:stitch2802
ID: 10851960
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/.
0
 
LVL 1

Accepted Solution

by:
rhanneken earned 500 total points
ID: 10852176
stitch2802,

This console application shows you how to get the information you want.  You may want to use something other than DISPLAY_DEVICE_ATTACHED_TO_DESKTOP; look up DISPLAY_DEVICE in the Platform SDK help files for more information.

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <ostream>

int _tmain(int argc, _TCHAR* argv[])
{
    DWORD iDevNum(0);
    DISPLAY_DEVICE dd;
    dd.cb = sizeof(dd);

    while ( EnumDisplayDevices(0, iDevNum, &dd, 0) )
    {
        if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
        {
            DISPLAY_DEVICE dd2;
            dd2.cb = sizeof(dd2);
            EnumDisplayDevices(dd.DeviceName, 0, &dd2, 0);
            std::cout << (iDevNum + 1) << ". " << dd2.DeviceString << std::endl;
        }
        ++iDevNum;
    }

    std::cin.get();

    return 0;
}

0
 

Author Comment

by:stitch2802
ID: 10852180
rhanneken,

You're a genius! =)

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now