14
votes

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?

3
You already wasted too much time on this. Just replace the video adapter. - Hans Passant
This Code Project article may be of help: codeproject.com/Articles/119168/Hardware-Change-Detection Although I'd agree with @HansPassant that it sounds like a hardware problem that it's not worth trying to work around with a software fix! - beercohol

3 Answers

5
votes

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.

4
votes

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.

0
votes

You should read this if you want to learn about display-aware apps.