DISPLAY_DEVICE main monitor StateFlags

Jeff Ibey 41 Reputation points

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 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.
1,907 questions
No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 5,851 Reputation points Microsoft Employee

    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

    Please refer to the same thread you ask.

    No comments

  2. Jeff Ibey 41 Reputation points

    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.