Fred-o Posted March 26, 2020 Share Posted March 26, 2020 Hello. I have this script that is supposed to "Show windows side by side". I use it when I have 2 Explorer windows open and need them to snap to sides of the screen. Sometimes it works but sometimes not as it's "supposed" to. Maybe it's lacking commands. $objShell = ObjCreate("Shell.Application") $objShell.TileVertically I discovered this other script that runs 2 instances of Windows Explorer side by side that works as it should. Local $hRun1 = _Run('Explorer.exe', 0, 0, @DesktopWidth/2, @DesktopHeight - 50) Local $hRun2 = _Run('Explorer.exe', @DesktopWidth/2, 0, @DesktopWidth/2, @DesktopHeight - 50) Func _Run($sRunCommand, $iX, $iY, $iW, $iH) Local $aWinList_Before = WinList("[CLASS:CabinetWClass]") Run($sRunCommand) Do $aWinList_After = WinList("[CLASS:CabinetWClass]") Until $aWinList_After[0][0] > $aWinList_Before[0][0] Local $hWnd = $aWinList_After[1][1] Sleep(1000) WinMove($hWnd, "", $iX, $iY, $iW, $iH) EndFunc I have very little knowledge of AutoIt scripting so I don't know how to apply the 2nd script to the 1st script so it behaves the same way. Would really appreciate your help. Thanks 😀 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 26, 2020 Moderators Share Posted March 26, 2020 (edited) In the explorer script, you would simply change "explorer.exe" to the name of your application. Then inside the function, change the class name to the class of the window you're after (Use the AutoIt Window Info Tool, in the same directory where you installed AutoIt, to find this information). For example, this works with Notepad: Local $hRun1 = _Run('notepad.exe', 0, 0, @DesktopWidth/2, @DesktopHeight - 50) Local $hRun2 = _Run('notepad.exe', @DesktopWidth/2, 0, @DesktopWidth/2, @DesktopHeight - 50) Func _Run($sRunCommand, $iX, $iY, $iW, $iH) Local $aWinList_Before = WinList("[CLASS:Notepad]") Run($sRunCommand) Do $aWinList_After = WinList("[CLASS:Notepad]") Until $aWinList_After[0][0] > $aWinList_Before[0][0] Local $hWnd = $aWinList_After[1][1] Sleep(1000) WinMove($hWnd, "", $iX, $iY, $iW, $iH) EndFunc Edited March 26, 2020 by JLogan3o13 SkysLastChance 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Exit Posted March 27, 2020 Share Posted March 27, 2020 Windows key + Left arrow or Right arrow: Snap selected window to the left or right half of the screen. Then select another window to fit the opposite half. Earthshine 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 6 hours ago, JLogan3o13 said: In the explorer script, you would simply change "explorer.exe" to the name of your application. Then inside the function, change the class name to the class of the window you're after (Use the AutoIt Window Info Tool, in the same directory where you installed AutoIt, to find this information). For example, this works with Notepad: Local $hRun1 = _Run('notepad.exe', 0, 0, @DesktopWidth/2, @DesktopHeight - 50) Local $hRun2 = _Run('notepad.exe', @DesktopWidth/2, 0, @DesktopWidth/2, @DesktopHeight - 50) Func _Run($sRunCommand, $iX, $iY, $iW, $iH) Local $aWinList_Before = WinList("[CLASS:Notepad]") Run($sRunCommand) Do $aWinList_After = WinList("[CLASS:Notepad]") Until $aWinList_After[0][0] > $aWinList_Before[0][0] Local $hWnd = $aWinList_After[1][1] Sleep(1000) WinMove($hWnd, "", $iX, $iY, $iW, $iH) EndFunc Sorry, maybe I wasn't clear. The script I am trying to achieve is just to move 2 Explorer windows side by side. Supposedly I already have 2 Explorer windows open. I just want to snap them both to the side of the screen. Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 10 minutes ago, Exit said: Windows key + Left arrow or Right arrow: Snap selected window to the left or right half of the screen. Then select another window to fit the opposite half. Thanks I am familiar with this keyboard shortcut. But I want to automate this with this AutoIt script and add it to my right click context menu. Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 I also tried this but it's still lacking... the 2nd window does not snap. 😯 $objShell = ObjCreate("Shell.Application") $objShell.TileVertically Send("#{LEFT}",0) Send("#{RIGHT}",0) Link to comment Share on other sites More sharing options...
Dionysis Posted March 27, 2020 Share Posted March 27, 2020 (edited) @Fred-o How do you select which two windows to tile? Do you only have two explorer windows every time you want to run this? Because with $objShell = ObjCreate("Shell.Application") $objShell.TileVertically Send("#{LEFT}",0) Send("#{RIGHT}",0) you send both to the (same) active window. Edited March 27, 2020 by Dionysis Link to comment Share on other sites More sharing options...
Nine Posted March 27, 2020 Share Posted March 27, 2020 9 hours ago, Fred-o said: The script I am trying to achieve is just to move 2 Explorer windows side by side. Supposedly I already have 2 Explorer windows open. I just want to snap them both to the side of the screen. #include <Constants.au3> SnapExplorer () If @error Then MsgBox ($MB_SYSTEMMODAL,"Error",@error) Func SnapExplorer () Local $aWin = WinList ("[CLASS:CabinetWClass]") If $aWin[0][0] <> 2 Then Return SetError (1) $iW = int(@DesktopWidth / $aWin[0][0]) $iH = @DesktopHeight - 40 For $i = 1 to $aWin[0][0] WinActivate ($aWin[$i][1]) WinMove ($aWin[$i][1],"", ($i-1)*$iW, 0,$iW, $iH, 1) Next EndFunc Try this Fred-o 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 4 hours ago, Dionysis said: @Fred-o How do you select which two windows to tile? Do you only have two explorer windows every time you want to run this? Because with $objShell = ObjCreate("Shell.Application") $objShell.TileVertically Send("#{LEFT}",0) Send("#{RIGHT}",0) you send both to the (same) active window. What's the correct command? Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 2 hours ago, Nine said: #include <Constants.au3> SnapExplorer () If @error Then MsgBox ($MB_SYSTEMMODAL,"Error",@error) Func SnapExplorer () Local $aWin = WinList ("[CLASS:CabinetWClass]") If $aWin[0][0] <> 2 Then Return SetError (1) $iW = int(@DesktopWidth / $aWin[0][0]) $iH = @DesktopHeight - 40 For $i = 1 to $aWin[0][0] WinActivate ($aWin[$i][1]) WinMove ($aWin[$i][1],"", ($i-1)*$iW, 0,$iW, $iH, 1) Next EndFunc Try this Always returns an error. Link to comment Share on other sites More sharing options...
Nine Posted March 27, 2020 Share Posted March 27, 2020 Which is ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 Link to comment Share on other sites More sharing options...
Nine Posted March 27, 2020 Share Posted March 27, 2020 It is because you do not have 2 explorer started. That was your assumption : 14 hours ago, Fred-o said: Supposedly I already have 2 Explorer windows open. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Exit Posted March 27, 2020 Share Posted March 27, 2020 13 hours ago, Fred-o said: I also tried this but it's still lacking... the 2nd window does not snap. 😯 $objShell = ObjCreate("Shell.Application") $objShell.TileVertically Send("#{LEFT}",0) Send("#{RIGHT}",0) Let it snap in: Send("#{LEFT}") Sleep(100) Send("{Enter}") App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 (edited) 1 hour ago, Nine said: It is because you do not have 2 explorer started. That was your assumption : My bad. All this time, I was testing the script with a Explorer window and a Firefox window open (thinking it will work with any 2 Windows open). You are right. IT WORKS! 😋 Thank you! Edited March 27, 2020 by Fred-o Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 47 minutes ago, Exit said: Let it snap in: Send("#{LEFT}") Sleep(100) Send("{Enter}") Sorry. First window snaps OK but the 2nd window covers just 1/3 of the monitor. It's OK though @Nine 's script works as it's supposed to. Thank you all for your help. 😄 Link to comment Share on other sites More sharing options...
Fred-o Posted March 27, 2020 Author Share Posted March 27, 2020 My context menu Link to comment Share on other sites More sharing options...
Fred-o Posted October 8, 2020 Author Share Posted October 8, 2020 I thought I'd post an update of changes I made to @Nine's script that I am currently using. I also renamed the script to "Show Explorer windows side by side" #include <Constants.au3> SnapExplorer () Func SnapExplorer () Local $aWin = WinList ("[CLASS:CabinetWClass]") If $aWin[0][0] <> 2 Then Exit MsgBox (16, "Error", "Open 2 instances of Explorer only") $iW = int(@DesktopWidth / $aWin[0][0]) $iH = @DesktopHeight - 40 For $i = 1 to $aWin[0][0] WinActivate ($aWin[$i][1]) WinMove ($aWin[$i][1],"", ($i-1)*$iW, 0,$iW, $iH, 1) Next EndFunc 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