Post Reply

Forums -> UltraMon™ SDK -> Alternate between laptop screen and dual monitors
Xfigio   2007-12-20 07:28
Hi all,

At work I have dual 19" monitors, but when traveling and at home, I use the laptop display. I wanted a way to easily switch between the two options, without having to go to my display properties each time, setting screens, and resolutions, then moving windows to the correct locations. I imagine that there are plenty of other people who'd like to do the same, as such, I've posted my script, which will detect my hardware, enable monitors, set resolutions and reposition windows. I hope it can be of help to others too. Bind the script to a hotkey (using WinKey), and I simple hit [Ctrl]+[Win]+[1] and walla, everything's set up again.

<job id="backup"> <script language="JScript" src="scriptLibrary.js"/> <script language="JScript"> var FINDWND_TITLE = 1; var FINDWND_CLASS = 2; dumpMonitors( false ); configMonitors(); function configMonitors() { var oSys = new ActiveXObject( "UltraMon.System" ); var oMonitorList = new Enumerator( oSys.Monitors ); var oLeft, oRight for (;!oMonitorList.atEnd(); oMonitorList.moveNext() ) { var oMon = oMonitorList.item(); switch( oMon.Name ) { case "Dell 1907FP(Analog)": oRight = oMon; break; case "Dell 1907FP(Digital)": oLeft = oMon break; case "Generic PnP Monitor": oMon.Enabled = true; oMon.Width = 1440; oMon.Height = 900; oSys.ApplyMonitorChanges(); moveWindow( FINDWND_CLASS, "QTool", 2395, 168 ); moveWindow( FINDWND_TITLE, "SamurizeClient-Glass", 2395, 446 ); //if it's only the laptop display, don't continue. return; } } //Now configure the external displays. oLeft.Enabled = true; oRight.Enabled = true; oLeft.Primary = true; oSys.ApplyMonitorChanges(); oLeft.Width = 1280; oLeft.Height = 1024; oRight.Width = 1280; oRight.Height = 1024; oLeft.Left = 0; oRight.Left = 1280; oLeft.Top = 0; oRight.Top =0 oSys.ApplyMonitorChanges(); moveWindow( FINDWND_CLASS, "QTool", 2403, 352 ); moveWindow( FINDWND_TITLE, "SamurizeClient-Glass", 2403, 631 ); } /************************************** Support Functions **************************************/ //Move window function moveWindow( iIdentifierType, sIdentifier, iPosX, iPosY ) { var oWnd = new ActiveXObject( "UltraMon.Window" ); switch( iIdentifierType ) { case FINDWND_TITLE: oWnd.find( sIdentifier, "", iIdentifierType, 0, 0 ); break; case FINDWND_CLASS: oWnd.find( "", sIdentifier, iIdentifierType, 0, 0 ); break; } if( !oWnd ) { WScript.Echo( 1 ); //If we can't find the window, there's not much point in continuing. return; } oWnd.Left = iPosX; oWnd.Top = iPosY; oWnd.ApplyChanges( 0 ); } //List monitor attributes function dumpMonitors( gShowInfo ) { var oSys = new ActiveXObject( "UltraMon.System" ); var oMonitorList = new Enumerator( oSys.Monitors ); var sOutput = ""; for (;!oMonitorList.atEnd(); oMonitorList.moveNext() ) { oMon = oMonitorList.item(); sOutput += "\n\nMonitor: " + oMon.ID; sOutput += "\nAdapterDeviceName: " + oMon.AdaptorDeviceName; sOutput += "\nAdapterName: " + oMon.AdapterName; sOutput += "\n" + "Colordepth: " + oMon.Colordepth; sOutput += "\n" + "Detached: " + oMon.Detached; sOutput += "\n" + "DeviceName: " + oMon.DeviceName; sOutput += "\n" + "DeviceRegKey: " + oMon.DeviceRegKey; sOutput += "\n" + "DisplayModes: " + oMon.DisplayModes; sOutput += "\n" + "Enabled: " + oMon.Enabled; sOutput += "\n" + "Height: " + oMon.Height; sOutput += "\n" + "HMonitor: " + oMon.HMonitor; sOutput += "\n" + "HwAccel: " + oMon.HwAccel; sOutput += "\n" + "ID: " + oMon.ID; sOutput += "\n" + "Left: " + oMon.Left; sOutput += "\n" + "Name: " + oMon.Name; sOutput += "\n" + "Primary: " + oMon.Primary; sOutput += "\n" + "RefreshRate: " + oMon.RefreshRate; sOutput += "\n" + "Removable: " + oMon.Removable; sOutput += "\n" + "Top: " + oMon.Top; sOutput += "\n" + "Width: " + oMon.Width; sOutput += "\n" + "WindowsID: " + oMon.WindowsID; //sOutput += "\n" + "WorkHeight: " + oMon.WorkHeight; //sOutput += "\n" + "WorkLeft: " + oMon.WorkLeft; //sOutput += "\n" + "WorkTop: " + oMon.WorkTop; //sOutput += "\n" + "WorkWidth: " + oMon.WorkWidth; } if( gShowInfo ) WScript.Echo( sOutput ); } </script> </job>
Atreus   2009-02-09 23:09
Would something like this work on a Vista PC with 2 monitors and a TV attached? As I can only have 2 displays at once for the video card (8800GT), I sometimes want video on the TV and 1 monitor, other times i want it on the two monitors.

Thus far, I've had to always use the Nvidia CP to change it, as the display that isn't being used doesn't show up in the windows settings -- only in the Nvidia CP. Thanks for any answers you may have!

There are many worlds, but they share the same sky- one sky, one destiny.
Christian Studer   2009-02-10 13:12
This won't work, UltraMon can't switch between output to the monitor and TV, you would need to do this via the video card software.

Christian Studer - www.realtimesoft.com
mirry   2009-05-15 00:38
Can you please tell me how to save this script?

mirry
Christian Studer   2009-05-15 08:59
Most likely in a text file with the .wsf extension, I'm not that familiar with this type of script myself though.

Christian Studer - www.realtimesoft.com
Forums -> UltraMon™ SDK -> Alternate between laptop screen and dual monitors

Post Reply