Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force display detection in Windows?

I often boot my Windows 7 PC with the attached KVM switch focused on another computer. When I switch to the booted PC, the display resolution is wrong (and the second attached monitor is not detected).

I can correct this by right-clicking the desktop, choosing Screen Resolution and clicking Detect. This makes Windows detect attached displays and adjust to the most optimal resolution.

I would like to write a small utility to do this automatically. Which Win32 API call or C# object should I use?

like image 366
Martin Wiboe Avatar asked Oct 04 '10 20:10

Martin Wiboe


3 Answers

You can try:

  1. You can use Spy++ to search for the windows that are open and take a look at their properties and messages.
  2. Use process to start "rundll32.exe shell32.dll,Control_RunDLL desk.cpl" or experiment with calling it directly to see if you can get a window handle, check below link for ideas.
  3. Use the code "send button click to external app" and modify it to search for a window with caption "Screen Resolution" and send a BN_CLICK to the childwindow with the caption "Detect".
  4. Since the computer is already on you might want to fire it up automatically on logon, for that use the task scheduler.
like image 57
Marlon Avatar answered Oct 06 '22 11:10

Marlon


This will get you half-way there:

Execute: control.exe desk.cpl,Settings,@Settings

That will bring up the Screen Resolution panel directly.

I might also suggest a scripting tool like http://en.wikipedia.org/wiki/Windows_Script_Host And write a utility that'll open the panel and click the button.

Barring that it's possible that the control panel directly calls into a windows .dll which you can load and invoke in code directly, but that would require some sleuthing to detect. (you can start by running the .cpl in a debugger and see what happens when you click the detect).

like image 40
Neal Tibrewala Avatar answered Oct 06 '22 09:10

Neal Tibrewala


Why not just use Do It Again and write a macro that resets the resolution for you by recording your mouse and keyboard actions?

like image 28
ander Avatar answered Oct 06 '22 10:10

ander