Jump to content

Recommended Posts

Posted

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 😀

 

 

  • Moderators
Posted (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 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!

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

 

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

Posted (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 by Dionysis
Posted
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

Posted
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?

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

 

Posted (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 by Fred-o
Posted
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. 😄

 

  • 6 months later...
Posted

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

 

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
  • Recently Browsing   0 members

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