14

I am trying to retrieve the monitor ID's as shown in the Windows display properties (#1, 2... etc), but I can't seem to find a way. I have tried using EnumDisplayMonitors as well as EnumDisplayDevices. They both return something like "\.\DISPLAY1". However, this number doesn't always match the number shown by Windows, especially when 2 video cards are being used to drive 3 or more monitors. Is there an API call I am missing to retrieve this information, or is there a way to get it from the registry or somewhere else? Thanks!

I have tried these methods:
Win32: EnumDisplayMonitors, EnumDisplayDevices: Neither of these return monitors that aren't active, and neither one returns the correct IDs.
WMI: "select * from Win32_DesktopMonitor" doesn't return all the monitors, and there is no ID.
Registry: I have found the monitors in various locations, none of the places I found have the info I am looking for.

Any help is much appreciated. :)

Update: These are the monitor numbers I am looking for: alt text

3
  • 1
    Old question, ever find an answer? Nov 1, 2011 at 21:33
  • 1
    Anybody ever find a solution?
    – flashk
    May 2, 2012 at 16:05
  • 1
    @JoelBarsotti, did you solve that problem? May 3, 2017 at 8:39

3 Answers 3

2

Depending on the purpose, you might want to look toward a driver-based solution. I know nVidia have some decent libs that gives you access to most of the functions un the control pannel.

1
  • This is an interesting idea, but I need something more general purpose and can't depend on specific drivers. Apr 9, 2010 at 18:57
1

Did you make two calls to EnumDisplayDevices? Try something like:

while (EnumDisplayDevices(0, dev, &dd, 0))
{
...
  while (EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0))
  {
   ...
  }
}
3
  • I have done this, but where does the monitor number get returned? Apr 9, 2010 at 18:56
  • What do you mean by monitor number? If the mentioned "devMon", then start with devMon = 0, and make devMon++ in the internal "while".
    – VitalyVal
    Apr 9, 2010 at 21:38
  • I have updated the question with a picture of the monitor numbers I am looking for. Apr 10, 2010 at 0:30
0

Just a guess, but it looks like Windows shows iDevNum+1 in Windows display properties.

4
  • Unfortunately this isn't the case, that would be too easy. :) If you have a dual monitor system, try making #2 your primary and disabling #1. #2 will still be called number 2 in the Display Properties window, but it will be the first monitor returned by EnumDisplayDevices (iDevNum 0). :( Apr 8, 2010 at 20:00
  • Also, the order that monitors are returned by EnumDisplayMonitors appears to be random. Most of the time it will return them in the same order, but if you have 2 video cards driving 3 monitors, it can change around. Apr 8, 2010 at 20:02
  • This lead me down the right path, but isn't correct for Windows 7. Apr 11, 2010 at 2:43
  • 6
    You wrote "lead me down the right path", but not what the right path is. I'm looking at the same problem right now, so I'd be rather interested in how you finally solved this :^)
    – Paul Groke
    Dec 22, 2010 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.