简体   繁体   中英

How can you get the display adapter used for a particular monitor in Windows?

On a Mac, I can use the following to print out the adapter used for a particular monitor:

io_registry_entry_t dspPort = CGDisplayIOServicePort(displays[i]);
CFDataRef model_;
model_ = (CFDataRef)IORegistryEntrySearchCFProperty(dspPort,kIOServicePlane,CFSTR("model"),
                                                    kCFAllocatorDefault,
                                                    kIORegistryIterateRecursively | kIORegistryIterateParents);

if (model_) {
  newLine();
  String model((const char*)CFDataGetBytePtr(model_), CFDataGetLength(model_));
  log.printf("Adapter: %s", model.buf);
  CFRelease(model_);
}

Example output- Adapter: AMD Radeon HD 6750M

Where displays[i] is populated using CGGetActiveDisplayList(nDisplays, displays, &nDisplays);

Is there any way to do the equivalent operation on Windows? I'm cycling through all displays using EnumDisplayMonitors .

I can get a list of adapters using EnumDisplayDevices , but how do I see which monitor is attached to which adapter?

Edit

Using:

for (int i=0; EnumDisplayDevicesA(monitorInfo.szDevice, i, &dev, 0); i++) {
    newLine();
    log.printf("Display Device: %s",(char*)dev.DeviceString);
  }

I can get the device names of the monitors themselves, but not the adapters they are connected to!

I can think of three approaches:

  1. The EnumDisplayDevices documentation mentions that the dwFlags argument can be used to get a device ID which can be used with the SetupAPI functions . That API provide a whole range of functions to get device information . So maybe you can get the device ID from EnumDisplayDevices , stick that into some SetupAPI function to get the monitor device struct, and get the display adapter device ID from there.

  2. You can probably use the Win32_VideoController class via WMI to get the display adapter information.

  3. I can imagine that some DirectX API is available for getting information about the installed graphics hardware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM