Jump to content

Span a window across two monitors


dreniarb
 Share

Recommended Posts

It's been a long time since I've contributed here, thought I would share this script I wrote.  I have a user that wanted to maximize Access across two monitors but no matter what we did Access would always open on just one monitor, then he'd have to drag the frame out to the other monitor.  This script will span the active window across both screens.  It assumes that both screens are the same size and writes those values to an ini file for later editing.  If one monitor is smaller than the other (this was the case with this guy) you can edit the file and put the other sizes in.  It'll span the windows height to whichever height is smaller.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=spanit.ico
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

if FileExists(@ScriptDir & "\spanit.ini") Then
    $LmWidth=IniRead(@ScriptDir & "\spanit.ini","LeftMon","Width",@DesktopWidth)
    $LmHeight=IniRead(@ScriptDir & "\spanit.ini","LeftMon","Height",@DesktopHeight)
    $RmWidth=IniRead(@ScriptDir & "\spanit.ini","RightMon","Width",@DesktopWidth)
    $RmHeight=IniRead(@ScriptDir & "\spanit.ini","RightMon","Height",@DesktopHeight)
Else
    $LmWidth=@DesktopWidth
    $LmHeight=@DesktopHeight
    $RmWidth=@DesktopWidth
    $RmHeight=@DesktopHeight
    IniWrite(@ScriptDir & "\spanit.ini","LeftMon","Width",$LmWidth)
    IniWrite(@ScriptDir & "\spanit.ini","LeftMon","Height",$LmHeight)
    IniWrite(@ScriptDir & "\spanit.ini","RightMon","Width",$RmWidth)
    IniWrite(@ScriptDir & "\spanit.ini","RightMon","Height",$RmHeight)
EndIf

if $LmHeight>$RmHeight Then
    $height=$LmHeight
Else
    $height=$RmHeight
EndIf

SplashTextOn("Span it - 5 second countdown","Click the window you want to span within 5 seconds.", 600,40,50,100, 1, "Arial", 5)
sleep(5000)
SplashOff()
$title=WinGetTitle("")
WinMove($title,"",0,0,$LmWidth+$RmWidth,$height)

If someone knows how to get the width and height of a second monitor that would be awesome.  I couldn't find a way.  But the settings only need fixed once, so it's not that big of a deal.

Link to comment
Share on other sites

$psize = WinGetPos("Program Manager")
SplashTextOn("Span it - 5 second countdown","Click the window you want to span within 5 seconds.", 600,40,50,100, 1, "Arial", 5)
sleep(5000)
SplashOff()
$title=WinGetTitle("")
WinMove($title,"",0,0, $psize[2],$psize[3])

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

If someone knows how to get the width and height of a second monitor that would be awesome. I couldn't find a way. But the settings only need fixed once, so it's not that big of a deal.

Perhaps this?

 

#include <array.au3>
Global $__MonitorList[1][1] = [[0]]
_ShowMonitorInfo()
_ArrayDisplay($__MonitorList)
Exit

;==================================================================================================
; Function Name:   _ShowMonitorInfo()
; Description::    Show the info in $__MonitorList in a msgbox (line 0 is entire screen)
; Parameter(s):    n/a
; Return Value(s): n/a
; Author(s):       xrxca (autoit@forums.xrx.ca)
;==================================================================================================
Func _ShowMonitorInfo()
    If $__MonitorList[0][0] == 0 Then
        _GetMonitors()
    EndIf
    Local $Msg = ""
    Local $i = 0
    For $i = 0 To $__MonitorList[0][0]
        $Msg &= $i & " - L:" & $__MonitorList[$i][1] & ", T:" & $__MonitorList[$i][2]
        $Msg &= ", R:" & $__MonitorList[$i][3] & ", B:" & $__MonitorList[$i][4]
        If $i < $__MonitorList[0][0] Then $Msg &= @CRLF
    Next
    ; MsgBox(0, $__MonitorList[0][0] & " Monitors: ", $Msg)
EndFunc   ;==>_ShowMonitorInfo

;==================================================================================================
; Function Name:   _GetMonitors()
; Description::    Load monitor positions
; Parameter(s):    n/a
; Return Value(s): 2D Array of Monitors
;                       [0][0] = Number of Monitors
;                       [i][0] = HMONITOR handle of this monitor.
;                       [i][1] = Left Position of Monitor
;                       [i][2] = Top Position of Monitor
;                       [i][3] = Right Position of Monitor
;                       [i][4] = Bottom Position of Monitor
; Note:            [0][1..4] are set to Left,Top,Right,Bottom of entire screen
;                  hMonitor is returned in [i][0], but no longer used by these routines.
;                  Also sets $__MonitorList global variable (for other subs to use)
; Author(s):       xrxca (autoit@forums.xrx.ca)
;==================================================================================================
Func _GetMonitors()
    $__MonitorList[0][0] = 0 ;  Added so that the global array is reset if this is called multiple times
    Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam")
    DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
    DllCallbackFree($handle)
    Local $i = 0
    For $i = 1 To $__MonitorList[0][0]
        If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1]
        If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2]
        If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3]
        If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4]
    Next
    Return $__MonitorList
EndFunc   ;==>_GetMonitors

;==================================================================================================
; Function Name:   _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
; Description::    Enum Callback Function for EnumDisplayMonitors in _GetMonitors
; Author(s):       xrxca (autoit@forums.xrx.ca)
;==================================================================================================
Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
    Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect)
    $__MonitorList[0][0] += 1
    ReDim $__MonitorList[$__MonitorList[0][0] + 1][5]
    $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor
    $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left")
    $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top")
    $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right")
    $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom")
    Return 1 ; Return 1 to continue enumeration
EndFunc   ;==>_MonitorEnumProc

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

All those functions are in AutoIt.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 5 months later...

This code works to span the active window over 2 monitors using a hotkey.

;~ Hotkey
;~ ------------------------------------------------------------------
HotKeySet("^+{UP}", "Resize_Window") ; CTRL+SHIFT+UP
;~ /-----------------------------------------------------------------

;~ Loop
;~ ------------------------------------------------------------------
While 1
    Sleep(1000)
WEnd
;~ /-----------------------------------------------------------------

;~ Functions
;~ ------------------------------------------------------------------
Func Resize_Window()
    WinSetState("[ACTIVE]","",@SW_RESTORE)
    WinMove("[ACTIVE]","",0,0,_WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN),_WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN))
EndFunc
;~ /-----------------------------------------------------------------
Edited by fling
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...