Tomas10 Posted October 5, 2017 Share Posted October 5, 2017 Hello! I'm new to auto it, I'm trying to order 6 windows named the same thing (only handle is different). I've sorted out Resizing and moving the first one, however i'd like the second one to get placed next to the first, and so on. And if I close one down I'd like the next one to take its place. Im a bit lost , mostly in the ordering part. Link to comment Share on other sites More sharing options...
Malkey Posted October 6, 2017 Share Posted October 6, 2017 (edited) For this example of Notepad windows to work for you, your window handles will need to be entered into the array, $aWinHwds. Press Esc key to exit this example when run. expandcollapse popup#include <Array.au3> HotKeySet("{ESC}", "_Terminate") ; Press Esc key to exit. Global $aWinHwds[6] ; <<<<< Change for the number of windows required. (eg. $aWinHwds[20] will generate 20 windows) Local $iNumOfCols = 4 ; <<<<< Change for number of columns of windows per row on desktop. Local $iWinWidth = Int(@DesktopWidth / $iNumOfCols), $iWinHeight = Int(@DesktopHeight / Ceiling(UBound($aWinHwds) / $iNumOfCols)) For $i = 0 To UBound($aWinHwds) - 1 $iPid = Run("notepad.exe") ProcessWait($iPid) $aWinHwds[$i] = WinGetHandle("", "") ; Add the active window's handle to $aWinHwds Array WinMove($aWinHwds[$i], "", Mod($i, $iNumOfCols) * $iWinWidth, Int($i / $iNumOfCols) * $iWinHeight, $iWinWidth + 13, $iWinHeight + 10) Next While 1 For $i = 0 To UBound($aWinHwds) - 1 If WinExists($aWinHwds[$i], "") = 0 Then ; Check if any windows have been deleted. _ArrayDelete($aWinHwds, $i) ; This re-dimensions the $aWinHwds array. ExitLoop ; Exits For-Next loop. Will re-order windows in next For-Next loop with new UBound($aWinHwds) value. Else WinMove($aWinHwds[$i], "", Mod($i, $iNumOfCols) * $iWinWidth, Int($i / $iNumOfCols) * $iWinHeight, $iWinWidth + 13, $iWinHeight + 10) EndIf Next If UBound($aWinHwds) = 0 Then ExitLoop ; Exit script if all generated windows have been deleted. Exits While-Wend loop. Sleep(50) WEnd Func _Terminate() ; Close all created windows For $i = UBound($aWinHwds) - 1 To 0 Step -1 WinClose($aWinHwds[$i], "") Next Exit EndFunc ;==>_Terminate Another method is right click on the bottom task bar near the right hand side of the desktop and a context menu will pop up. To re-arrange the windows on the desktop select either:- Cascade windows, Show windows stacked, Show windows side by side, or, Show the desktop, from the menu. And another shell object method. ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb774094(v=vs.85).aspx $objShell = ObjCreate("Shell.Application") $objShell.ToggleDesktop ; Show desktop Sleep(2000) $objShell.ToggleDesktop ; Re-instste previous desktop MsgBox(0, "ToggleDesktop 2nd time", "", 2) $objShell.TileHorizontally MsgBox(0, "TileHorizontally", "", 2) $objShell.TileVertically MsgBox(0, "TileVertically", "", 2) $objShell.CascadeWindows MsgBox(0, "CascadeWindows", "", 2) MsgBox(0, "The End", "Sorry about messing up all your windows", 2) Edited October 8, 2017 by Malkey Added two more methods. Tomas10 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now