How can I get monitors numbers from Screen Resolution dialog in win7 programmatically?
Asked Answered
M

3

12

When you press Identify button in Screen Resolution dialog then Windows shows you big white monitor numbers on each monitor. It was easy to find them programmatically together with monitor coordinates in Windows XP (with EnumDisplayDevices) but on Windows 7 it's broken. How can I do that?

  1. EnumDisplayDevices and GetMonitorInfo are not reliable anymore for that purpose in Windows 7.
  2. I tried GetMonitorInfo and then extracting monitor number from MONITORINFOEX.szDevice (I.E. \.\Display2) with no success. Another guy did that too two years ago and claimed that getMonitorInfo has a bug. This bug was marked as fixed by Microsoft without any comments but it still can be reproduced on a win7 machine having latest updates. (Btw, can anybody tell me - maybe this bug is absent on win8 ?)
  3. I tried QueryDisplayConfig from new CCD API but didn't find needed info.

Does anybody know the way?

Marti answered 5/7, 2012 at 15:57 Comment(1)
possible duplicate of How can I retrieve monitor information?Computerize
T
5

Windows does not provide a function that allows applications to obtain the numbers used by the display settings app. The numbers themselves are specific only to the display settings app and have no meaning in the system or in the CCD APIs used to query/set the display topology.

The best option is for applications to define their own criteria for assigning an index when prompting the user to select a display.

Trigg answered 17/6, 2019 at 22:1 Comment(1)
So "You can't" is still be the right answer. I'm sad :(Nameplate
F
2

I have never wanted to know in my Windows applications the number of monitors, but you can call GetSystemMetrics function with parameter value SM_CMONITORS to get the number of display monitors on a desktop.

I call in my Windows applications function GetSystemMetrics mainly with the parameter values SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN and SM_YVIRTUALSCREEN to avoid opening application windows completely or partly outside the display area. An application window could be nevertheless not visible if the user has extended the display area over multiple monitors, but not all of them are turned on.

The SystemParametersInfo function with value SPI_GETWORKAREA for uiAction parameter is also very useful to know where an application window can be positioned and how large it can be in width and height on primary screen without being partly hidden by other windows (bars) being always on top.

See also GetMonitorInfo function if more information from the monitors are required in your Windows application.

Fir answered 25/1, 2014 at 20:7 Comment(0)
H
0

For Windows versions supporting WDDM, which Windows 7 does, you can simply use DXGI which is part of DirectX. DXGI allows you to very easily enumerate the existing display adapters, the available display outputs per adapter and the supported display modes per display output. While enumerating there's a lot of additional data you can read out, like handles, identifiers and device names. All of this can easily be used to retrieve the working areas as well. The order in which adapters and outputs are enumerated is defined by the system and matches the order of your configuration screen.

See here for more information: MSDN DXGI Overview

Horan answered 25/1, 2015 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.