Jump to content
Sign in to follow this  
vladedoty

How do I make an array of windows move into correct positioning?

Recommended Posts

vladedoty

i have and array of window names and would like them to move into the correct x and y positions on my screen

I use the WinMove function but doesn't seem to be helping much.

It won't move any of the windows.

Is there a more effective way to write the code or use a different function?

Here is an example:

#include <array.au3>

Global $WinNames[4]
Global $handleWin[4]
Global $a, $winNum
Global $positionx[4]
Global $positiony[4]

$positionx[0] = "0"
$positiony[0] = "0"
$positionx[1] = "478"
$positiony[1] = "0"
$positionx[2] = "0"
$positiony[2] = "478"
$positionx[3] = "218"
$positiony[3] = "0"

$WinNames[0] = GUICreate("hello", 200, 400)
$WinNames[1] = GUICreate("hello", 100, 200)
$WinNames[2] = GUICreate("hello", 300, 400)
$WinNames[3] = GUICreate("hello", 300, 500)

For $a = 0 to 3
$winNum = WinGetTitle($WinNames[$a], "")
$handleWin[$a] = WinGetHandle($WinNames[$a], "")
WinMove($handleWin[$a], "", $positionx[$a], $positiony[$a])
Next
Edited by vladedoty

Share this post


Link to post
Share on other sites
Yashied

With something like this.

Dim $aPos[4][2] = [[0, 0], [478, 0], [0, 478], [218, 0]]
Dim $aWnd[4]

$aWnd[0] = GUICreate("hello", 200, 400)
$aWnd[1] = GUICreate("hello", 100, 200)
$aWnd[2] = GUICreate("hello", 300, 400)
$aWnd[3] = GUICreate("hello", 300, 500)

...

For $i = 0 To UBound($aWnd) - 1
    WinMove($aWnd[$i], "", $aPos[$i][0], $aPos[$i][1])
Next

EDIT:

For $i = 0 To UBound($aWnd) - 1
Edited by Yashied

Share this post


Link to post
Share on other sites
vladedoty

With something like this.

Dim $aPos[4][2] = [[0, 0], [478, 0], [0, 478], [218, 0]]
Dim $aWnd[4]

$aWnd[0] = GUICreate("hello", 200, 400)
$aWnd[1] = GUICreate("hello", 100, 200)
$aWnd[2] = GUICreate("hello", 300, 400)
$aWnd[3] = GUICreate("hello", 300, 500)

...

For $i = 0 To UBound($aWnd)
    WinMove($aWnd[$i], "", $aPos[$i][0], $aPos[$i][1])
Next

Thx for the quick resonse

but how is this any different?

Share this post


Link to post
Share on other sites
danielkza

With something like this.

Dim $aPos[4][2] = [[0, 0], [478, 0], [0, 478], [218, 0]]
Dim $aWnd[4]

$aWnd[0] = GUICreate("hello", 200, 400)
$aWnd[1] = GUICreate("hello", 100, 200)
$aWnd[2] = GUICreate("hello", 300, 400)
$aWnd[3] = GUICreate("hello", 300, 500)

...

For $i = 0 To UBound($aWnd)
    WinMove($aWnd[$i], "", $aPos[$i][0], $aPos[$i][1])
Next

Be careful with arrays: their indexes are 0-based, which means you must use UBound($array)-1, or you'll end up with a fatal error.

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
Yashied

...but how is this any different?

$positionx[0] = "0"
$positiony[0] = "0"
$positionx[1] = "478"
$positiony[1] = "0"
$positionx[2] = "0"
$positiony[2] = "478"
$positionx[3] = "218"
$positiony[3] = "0"

Think of it what are you doing?

Share this post


Link to post
Share on other sites
vladedoty

$positionx[0] = "0"
$positiony[0] = "0"
$positionx[1] = "478"
$positiony[1] = "0"
$positionx[2] = "0"
$positiony[2] = "478"
$positionx[3] = "218"
$positiony[3] = "0"

Think of it what are you doing?

Well the thing is that all $positionx and $positiony elements are input boxes.

so something like this so they will always change based on the users input

Global $x1Txt = GUICtrlCreateInput("0", 255, 299, 33, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $x2Txt = GUICtrlCreateInput("0", 255, 323, 33, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $y1Txt = GUICtrlCreateInput("0", 327, 299, 33, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $y2Txt = GUICtrlCreateInput("201", 327, 323, 33, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL))

$positionx[0] = ControlGetText($mainGui, "", $x1Txt)
$positiony[0] = ControlGetText($mainGui, "", $y1Txt)
$positionx[1] = ControlGetText($mainGui, "", $x2Txt)
$positiony[1] = ControlGetText($mainGui, "", $y2Txt)

Share this post


Link to post
Share on other sites
Yashied
vladedoty

Oh, sorry, could not see $positionx and $positiony.

so is there no difference then?

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
vladedoty

$handleWin[$a] = WinGetHandle($WinNames[$a], "")

This line is totally useless.

GUICreate() returns a handle of the window.

well i tried it again and the first window moves to the correct position,

however when the second window opens it doesn't move at all. along with the 3rd and fourth.

Share this post


Link to post
Share on other sites
picea892

Make sure the windows are open before you try to move them. You might need a winwait or sleep

Share this post


Link to post
Share on other sites
Malkey

i have and array of window names and would like them to move into the correct x and y positions on my screen

I use the WinMove function but doesn't seem to be helping much.

It won't move any of the windows.

Is there a more effective way to write the code or use a different function?

Here is an example:

#include <array.au3>

Global $WinNames[4]
Global $handleWin[4]
Global $a, $winNum
Global $positionx[4]
Global $positiony[4]

$positionx[0] = "0"
$positiony[0] = "0"
$positionx[1] = "478"
$positiony[1] = "0"
$positionx[2] = "0"
$positiony[2] = "478"
$positionx[3] = "218"
$positiony[3] = "0"

$WinNames[0] = GUICreate("hello", 200, 400)
$WinNames[1] = GUICreate("hello", 100, 200)
$WinNames[2] = GUICreate("hello", 300, 400)
$WinNames[3] = GUICreate("hello", 300, 500)

For $a = 0 to 3
$winNum = WinGetTitle($WinNames[$a], "")
$handleWin[$a] = WinGetHandle($WinNames[$a], "")
WinMove($handleWin[$a], "", $positionx[$a], $positiony[$a])
Next

This example appears to work.

;
#include <array.au3>

Global $aHandleWin[4]
Global $a
Global $aPositionX[4]
Global $aPositionY[4]

$aPositionX[0] = "0"
$aPositionY[0] = "0"
$aPositionX[1] = "478"
$aPositionY[1] = "0"
$aPositionX[2] = "0"
$aPositionY[2] = "478"
$aPositionX[3] = "218"
$aPositionY[3] = "0"

$aHandleWin[0] = GUICreate("hello", 200, 400)
GUISetState(@SW_SHOW)
$aHandleWin[1] = GUICreate("hello", 100, 200)
GUISetState(@SW_SHOW)
$aHandleWin[2] = GUICreate("hello", 300, 400)
GUISetState(@SW_SHOW)
$aHandleWin[3] = GUICreate("hello", 300, 500)
GUISetState(@SW_SHOW)

For $a = 0 To 3
    WinMove($aHandleWin[$a], "", $aPositionX[$a], $aPositionY[$a], Default, Default, 5)
Next

While GUIGetMsg() <> -3
WEnd
;

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.