Jump to content
kdot

[Help] Put windows next to other other?

Recommended Posts

kdot

I'm new to autoit. 

I have 10 chrome processes which open @ 400x545 . How can I put them next to each other automatically (as shown in the attachment). 

Res: 2560 x 1440 
Class: Chrome_WidgetWin_1

Thanks

screen.PNG

Share this post


Link to post
Share on other sites
TheXman

Have a look at the WinMove function.

WinMove ( "title", "text", x, y [, width [, height [, speed]]] )

 

Share this post


Link to post
Share on other sites
kdot
1 minute ago, TheXman said:

Have a look at the WinMove function.

WinMove ( "title", "text", x, y [, width [, height [, speed]]] )

 

Can you have it set the x and y automatically based on the resolution?

Share this post


Link to post
Share on other sites
TheXman

It's a function.  You set the x and y when you write the command.  You can base the x,y, w, and h based on the previous window's x,y,w,and h.  You can get that info using the WinGetPos function.

Edited by TheXman

Share this post


Link to post
Share on other sites
kdot

I've got the position and title of window 1 & 2 but get an error when running it.  Is there something else I have to include? 

WinMove ( "Example" -7, 1)
WinMove ( "Example" 379, 2)

Share this post


Link to post
Share on other sites
TheXman

The WinMove command has 4 required parameters.

WinMove ( "title", "text", x, y [, width [, height [, speed]]] )

Also, if you have multiple windows with the same title, you will probably want to use the INSTANCE property of the advanced window description title.

Refer to: https://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

 

Edited by TheXman

Share this post


Link to post
Share on other sites
kdot

I don't need to set the width or height I only need to move each window. 

Share this post


Link to post
Share on other sites
TheXman
2 minutes ago, kdot said:

I don't need to set the width or height I only need to move each window. 

The command has 4 required parameters: title, text, x and y.  If you aren't using the text parameter, then use "".

 

The help file examples are very useful.

Edited by TheXman

Share this post


Link to post
Share on other sites
TheXman

Here's a very simple example using notepad windows.

#include <Array.au3>

;Launch 4 notepad windows
Run("notepad.exe")
Run("notepad.exe")
Run("notepad.exe")
Run("notepad.exe")

;Wait a couple of seconds for the windows to load
Sleep(2000)

;Get a list of the window handles
Local $aWinList = WinList("Untitled - Notepad")
_ArrayDisplay($aWinList)

;Resize and move windows
WinMove($aWinList[1][1], "",   0,   0, 200, 200)
WinMove($aWinList[2][1], "", 200,   0, 200, 200)
WinMove($aWinList[3][1], "",   0, 200, 200, 200)
WinMove($aWinList[4][1], "", 200, 200, 200, 200)

Since I'm not sure how new to AutoIt you are, when you see the display of the array, close it, and the script will continue.

Edited by TheXman
  • Like 1

Share this post


Link to post
Share on other sites
kdot

That seems to work. thanks. 

Share this post


Link to post
Share on other sites
kdot
On 2/19/2018 at 10:13 PM, TheXman said:

Here's a very simple example using notepad windows.

#include <Array.au3>

;Launch 4 notepad windows
Run("notepad.exe")
Run("notepad.exe")
Run("notepad.exe")
Run("notepad.exe")

;Wait a couple of seconds for the windows to load
Sleep(2000)

;Get a list of the window handles
Local $aWinList = WinList("Untitled - Notepad")
_ArrayDisplay($aWinList)

;Resize and move windows
WinMove($aWinList[1][1], "",   0,   0, 200, 200)
WinMove($aWinList[2][1], "", 200,   0, 200, 200)
WinMove($aWinList[3][1], "",   0, 200, 200, 200)
WinMove($aWinList[4][1], "", 200, 200, 200, 200)

Since I'm not sure how new to AutoIt you are, when you see the display of the array, close it, and the script will continue.

Is it possible to do something more advanced like grab the current resolution and move each window to fill the entire monitor? 

Share this post


Link to post
Share on other sites
TheXman
50 minutes ago, kdot said:

Is it possible to do something more advanced like grab the current resolution and move each window to fill the entire monitor? 

Yes, that's possible.

You can get the monitor resolution and workable area info by using the _WinAPI_GetMonitorInfo function.  Then, it's just a matter of calculation the window size and positions.

Edited by TheXman

Share this post


Link to post
Share on other sites
TheXman

The example below should give you a decent starting point.  I left out some of the fun parts like getting the monitor's resolution and calculating what your width and height should be.   I mean, why should I have all of the fun, right?  ;)

 

#include <Array.au3>

example()

Func example()
    Const $kWIDTH  = 250
    Const $kHEIGHT = 300

    Local $aWinList
    Local $iRow, $iCol, $iIndex, $iX, $iY

    ;Launch 10 notepad windows
    For $i = 1 To 10
        Run("notepad.exe")
    Next

    ;Wait a couple of seconds for the windows to load
    Sleep(2000)

    ;Get a list of the window handles
    $aWinList = WinList("Untitled - Notepad")
;~  _ArrayDisplay($aWinList)

    ;Display 2 x 5 array of windows
    $iIndex = 0
    For $iRow = 0 To 1
        For $iCol = 0 To 4
            ;Resize and move windows into place
            $iIndex += 1
            $iX      = $iCol * $kWIDTH
            $iY      = $iRow * $kHEIGHT
            WinMove($aWinList[$iIndex][1], "", $iX, $iY, $kWIDTH, $kHEIGHT)
        Next
    Next
EndFunc

 

Share this post


Link to post
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

×