DISPLAY_DEVICE main monitor StateFlags

Jeff Ibey 41 Reputation points
2021-06-15T19:18:17.813+00:00

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 - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,412 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,256 Reputation points Microsoft Vendor
    2021-06-24T01:44:36.18+00:00

    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.


2 additional answers

Sort by: Most helpful
  1. Song Zhu - MSFT 906 Reputation points
    2021-06-16T08:06:02.257+00:00

    Please refer to the same thread you ask.

    0 comments No comments

  2. Jeff Ibey 41 Reputation points
    2021-06-17T05:37:48.627+00:00

    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.