Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect all connected monitors using Windows API

Tags:

winapi

I am using Windows 7. When I plug a new monitor when the PC is running, the monitor is not automatically detected. I must go to the Display->Screen Resolution and click on the Detect button in order to detect the monitor with the registry configuration.

I am searching for a way to do the same programmatically using the Windows API. So I would like to write a program that detects all connected monitors reproducing the Detect button. I tried using ChangeDisplaySettingEx but with bad results. Any suggestions?

like image 480
DOFHandler Avatar asked Jun 09 '15 07:06

DOFHandler


People also ask

How do I get Windows to recognize multiple monitors?

Select Start , then open Settings . Under System , select Display . Your PC should automatically detect your monitors and show your desktop. If you don't see the monitors, select Multiple displays , then Detect.

How do I detect other monitors?

Detect a display If you connected another display and it isn't showing in Settings, select Start > Settings > System > Display > Rearrange your displays, then select Detect.

Can Windows 10 detect 4 monitors?

Windows 10 has several features and settings to support one, two, three, four, and even more monitors without the need for third-party software for the best experience.

Why Cannot detect multiple displays?

A buggy, outdated, or corrupted graphics driver can cause problems that may prevent Windows 10 from detecting a second monitor automatically. The easiest method to fix this issue is updating, reinstalling, or downgrading the driver.


2 Answers

Not really a WinApi but try this utility:

C:\Windows\System32\DisplaySwitch.exe

DisplaySwitch.exe /internal - Switch to Primary only
DisplaySwitch.exe /external - Switch to Secondary only
DisplaySwitch.exe /clone - Clone desktop on both screens (Not HDCP compliant!)
DisplaySwitch.exe /extend - Extend desktop to both screens

In particular, try /extend switch, it should perform detection internally.

like image 183
Eldarien Avatar answered Sep 21 '22 07:09

Eldarien


Not an API solution, but you can use MS's DevCon utility on the command line to scan for new hardware.

https://support.microsoft.com/en-us/kb/311272

Download it from that page, then just execute this from a cmd window:

devcon.exe rescan

You can easily create a .bat or .cmd file to run this from a link.

like image 34
beercohol Avatar answered Sep 24 '22 07:09

beercohol