tuket
tuket

Reputation: 3941

Why does EnumDisplayDevices return so many results?

I have a Windows computer with an Nvidia card and an Intel card. Each GPU has one screen connected to it.

Then I use the following code to list all the display devices:

DISPLAY_DEVICE lDevice;
lDevice.cb = sizeof(DISPLAY_DEVICE);
int i = 0;
while (EnumDisplayDevices(NULL, i, &lDevice, EDD_GET_DEVICE_INTERFACE_NAME) != 0) {
    printf(
        "i: %d\n"
        "cb: %d\n"
        "DeviceName: %s\n"
        "DeviceString: %s\n"
        "StateFlags: %d\n"
        "DeviceID: %s\n"
        "DeviceKey: %s\n",
        i,
        lDevice.cb,
        lDevice.DeviceName,
        lDevice.DeviceString,
        lDevice.StateFlags,
        lDevice.DeviceID,
        lDevice.DeviceKey
    );
    i++;
}

This is the output:

i: 0
cb: 424
DeviceName: \\.\DISPLAY1
DeviceString: Intel(R) HD Graphics 4600
StateFlags: 134217729
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{3C36D58A-5C95-11EB-ACEC-B083FE9A7909}\0000
i: 1
cb: 424
DeviceName: \\.\DISPLAY2
DeviceString: Intel(R) HD Graphics 4600
StateFlags: 0
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{3C36D58A-5C95-11EB-ACEC-B083FE9A7909}\0001
i: 2
cb: 424
DeviceName: \\.\DISPLAY3
DeviceString: NVIDIA GeForce GTX 1060 3GB
StateFlags: 5
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{46FC15D3-C98C-11E9-ACCA-D1E7BCEC4649}\0000
i: 3
cb: 424
DeviceName: \\.\DISPLAY4
DeviceString: NVIDIA GeForce GTX 1060 3GB
StateFlags: 0
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{46FC15D3-C98C-11E9-ACCA-D1E7BCEC4649}\0001
i: 4
cb: 424
DeviceName: \\.\DISPLAY5
DeviceString: NVIDIA GeForce GTX 1060 3GB
StateFlags: 0
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{46FC15D3-C98C-11E9-ACCA-D1E7BCEC4649}\0002
i: 5
cb: 424
DeviceName: \\.\DISPLAY6
DeviceString: NVIDIA GeForce GTX 1060 3GB
StateFlags: 0
DeviceID: 
DeviceKey: \Registry\Machine\System\CurrentControlSet\Control\Video\{46FC15D3-C98C-11E9-ACCA-D1E7BCEC4649}\0003

I don't understand why there are 6 display devices, 2 for the Intel card and 4 for the Nvidia card. I think I'm probably missunderstanding the concept of display devices.

Here's the full code: https://gist.github.com/tuket/0cc2f9b77a4a6a82a72655941547e292

Upvotes: 1

Views: 627

Answers (1)

rogerdpack
rogerdpack

Reputation: 66771

using StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP did seem to work for me.

demo https://github.com/rdp/enumdisplaydevices_console_app

Upvotes: 2

Related Questions