question

JeffIbey-2039 avatar image
0 Votes"
JeffIbey-2039 asked JeffIbey-2039 commented

DISPLAY_DEVICE main monitor StateFlags

I am trying to draw on any monitor not the main monitor. I use the DISPLAY_DEVICE pointer and run through all 10 ports. I check
if (EnumDisplayDevices(0, [0-9],&DISPLAY_DEVICE,0)!=NULL)
If this is true, that means I found a connected display. I than check the StateFlags for main monitor by checking the third bit set.
If(!(DISPLAY_DEVICE.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))

If it's not set and a display, it's not the main monitor.
If it is set and a display, it is the main monitor.

I am running into the opposite in one scenario. The main display is identity number as 2, and it does not have the third bit set. So it's drawing on the main monitor when I am looking for ANYTHING but the main monitor. I know usually identity numbers are meaningless, however out of 70 machines only one acts this way. Am I understanding this wrong or does windows have a bug here the main monitor is set to identity 2 and does not set the 3rd bit in the state flags?

windows-api-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

XiaopoYang-MSFT avatar image
0 Votes"
XiaopoYang-MSFT answered JeffIbey-2039 commented

Thank for your attached code!
And according to the StateFlags of DISPLAY_DEVICEA structure,

DISPLAY_DEVICE_PRIMARY_DEVICE: The primary desktop is on the device. For a system with a single display card, this is always set. For a system with multiple display cards, only one device can have this set.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I rechecked your documentation, seems someone has updated the thread haha. Based on my old code that is how it was explained, however they have now added these 2 new paragraphs:

This paragraph answers my current question, thank you guys.

To obtain information on a display monitor, first call EnumDisplayDevices with lpDevice set to NULL. Then call EnumDisplayDevices with lpDevice set to DISPLAY_DEVICE.DeviceName from the first call to EnumDisplayDevices and with iDevNum set to zero. Then DISPLAY_DEVICE.DeviceString is the monitor name.


To query all monitor devices associated with an adapter, call EnumDisplayDevices in a loop with lpDevice set to the adapter name, iDevNum set to start at 0, and iDevNum set to increment until the function fails. Note that DISPLAY_DEVICE.DeviceName changes with each call for monitor information, so you must save the adapter name. The function fails when there are no more monitors for the adapter.

Thanks for your support!

0 Votes 0 ·
SongZhu-MSFT avatar image
0 Votes"
SongZhu-MSFT answered

Please refer to the same thread you ask.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeffIbey-2039 avatar image
0 Votes"
JeffIbey-2039 answered JeffIbey-2039 commented

Same thread? This completely different scenario with usage of state flags and lpDisplayDevice pointer. If you don't understand the use case or the differences between them please do not lump them.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Maybe you can provide a sample to reproduce the problem so that we can understand your problem.

0 Votes 0 ·
            DISPLAY_DEVICE dd;
     ZeroMemory(&dd, sizeof(dd));
     dd.cb = sizeof(dd);
     //check 10 ports
     int displayDevicePort=0;
     for(int i =0; i <10; i++) {
         //check ports are connected
         if(EnumDisplayDevices(0, i, &dd, 0)!=NULL) {
             //check if not main display
             if(!(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
                 //found extended display break out
                 //EnumDisplayDevices(0, 1, &dd, 0);
                 break;
             } else {
                 ZeroMemory(&dd, sizeof(dd));
                 dd.cb = sizeof(dd);
             }

         } 
     }
0 Votes 0 ·