Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 573
boqapt Avatar asked Jul 05 '12 15:07

boqapt


People also ask

How do I find my monitor number?

1. Find and record the model number of your monitor, it will be printed along the top or bottom edge of the monitor, or on a sticker on the back of the monitor.

How does Windows determine Display number?

The numbering for monitors identity depends on which port of your computer's graphics card the monitor is plugged into. For example, the port that monitor #1 is connected-to will always be #1. The only solution for changing identities is to swap the monitors, meaning connect them to different ports.

How do I match my screen resolution?

In the Control Panel window, click System, and then click Display. Select the monitor that you want to change, if more than one monitor is connected to your computer. Click the Resolution drop-down box to see a list of recommended resolutions for that display. Click the resolution that you want, and then click Apply.

How do I Auto Detect my screen resolution?

Go to 'settings,' then click 'system,' then click 'display,' then 'advanced display settings. ' The recommended resolution is your native resolution, and the one that you should be using.


2 Answers

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.

like image 169
Dave Anderson Avatar answered Sep 21 '22 17:09

Dave Anderson


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 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 informations from the monitors are required in your Windows application.

like image 45
Mofi Avatar answered Sep 20 '22 17:09

Mofi