Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate Dual Monitor Setup In Vista

I use a laptop as my primary workstation. Sometimes I work alone on it, but a significant portion of the time, I'm at my office desk and I hook up an external monitor to increase my workspace.

Every time I perform this action, I click the same dialog boxes in Windows Vista to setup the dual screen and position the window. It seems like a repeatable task that I could automate.

I'd like to be able to plug in my monitor cable, double click a program and have it automatically configure the monitor.

What type of program could do this? I haven't found much online that relates. I'm thinking of trying an autohotkey script, or the Windows Accessibility API with PowerShell. Has this problem already been solved?

Clarification: I'm specifically looking to automate the steps I use with my mouse that invoke the base functionality in Windows Vista.

  1. Right click on desktop
  2. Select Personalize in context menu
  3. Click display settings
  4. Click monitor #2, then click checkbox to "Extend desktop to this monitor"
  5. Click and drag monitor #2 to the left of monitor #1
  6. Click OK to close the dialog
  7. Click Yes in the subsequent pop up to accept these monitor settings

Update: Windows 7 does this automatically

I just upgraded to Windows 7 and it remembered my dual monitor settings. I set them once at work as listed above, then unplugged and worked at home over the weekend. I came in on Monday morning, booted up, plugged in and whammo! It just worked. Thanks Windows 7!

like image 471
a7drew Avatar asked Nov 15 '22 16:11

a7drew


1 Answers

I haven't seen an existing utility that does this but it would be pretty easy to write one using the Win32 APIs. Via this page, EnumDisplayDevices gets a list of display devices, EnumDisplaySettingsEx gets the current settings and ChangeDisplaySettingsEx will make the changes.

The DEVMODE.dmPosition field should contain the virtual coordinates of the top left corner of the display, with the primary monitor always being (0,0) and the others relative to that.

The tool would need two modes, the first saves the current settings to a config file, and the second applies the settings from the config. I'd store/retrieve only the display device index, name, and each of the DEVMODE.dm* fields mentioned in the ChangeDisplaySettingsEx docs. A text-based config allows for hand-edits.

like image 196
devstuff Avatar answered Dec 06 '22 19:12

devstuff