Jump to content

Show windows side by side


Recommended Posts

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

  • Moderators

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 by JLogan3o13

"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

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

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

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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 by Fred-o
Link to comment
Share on other sites

  • 6 months later...

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

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...