Sign in to follow this  
Followers 0
JAFN

Help Aligning Windows

3 posts in this topic

Assume multiple identical windows who's titles all start with '(-)'

I am trying to make it so that the windows align under the window cloesest to the top of the screen.

Can anyone show me what is wrong with the code below?

#Include <Array.au3>

OrderWindow("(-)")

Func OrderWindows($Mark)

    $List = WinList($Mark)
    $Items = $List[0][0]
    If $Items <= 2 Then Return
    ;YPos[x][0] = HWND
    ;    [x][1] = Top position
    Dim $YList[$Items][2]
    ; create an Array of hwnd and y position
    For $x = 0 to $Items - 1
        $WinPos = WinGetPos($List[$x+1][1])
        $YList[$x][0] = $List[$x+1][1] ;hwnd
        $YList[$x][1] = $WinPos[1]  ;y cord
;       MsgBox(0,"", $YList[$x][0] & " | " & $YList[$x][1])
    Next
    ;order array by highest window
    _ArraySort($YList, 0, 0, 0, 1)
    ;align all windows that titles start with $mark to align under the window highest on screen
    ;windows are all instances of the same script and are the same height
    $Left = $YList[0][1]
    For $x = 1 To $Items-1 ; start at 1 because 0 is the head
        $WinPos = WinGetPos($YList[$x][0])
        $Top  = $WinPos[1]; + $WinPos[3]
        $Left = $WinPos[0]
        WinMove($YList[$x][0],"", $Left, $Top)
    Next
EndFunc

[size="2"]The second mouse gets the cheese[/size]

Share this post


Link to post
Share on other sites



JAFN,

Can anyone show me what is wrong with the code below?

Your coordinates for repositioning the other GUIs is all wrong. Take a look at this script which shows how I would do it: :>

#Include <Array.au3>

#include <GUIConstantsEx.au3>

For $i = 1 To 3
    $hGUI = GUICreate("(-)Test " & $i, 200, 100)
    GUISetState()
Next

Sleep(5000) ; Allows you rearrange the GUIs you have just created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

OrderWindows("(-)")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func OrderWindows($Mark)

    ; get list of GUIs
    Local $List = WinList($Mark)
    $Items = $List[0][0]
    If $Items <= 2 Then Return

    ; Create an Array of hwnd and y position
    Local $YList[$Items + 1][2]
    For $x = 1 to $Items
        $WinPos = WinGetPos($List[$x][1])
        $YList[$x][0] = $List[$x][1] ;hwnd
        $YList[$x][1] = $WinPos[1]  ;y cord
    Next

    ; Order array by highest window
    _ArraySort($YList, 0, 0, 0, 1)

    ; Get position of highest GUI
    $aBasePos = WinGetPos($YList[1][0])

    _ArrayDisplay($aBasePos) ; For interest on;y

    ; Now reposition the other GUIs
    For $x = 2 To $Items
        ; We use the same X coord and add the height of the GUI to each successive GUI to get the Y coord
        WinMove($YList[$x][0], "", $aBasePos[0], $aBasePos[1] + ($aBasePos[3] * ($x - 1)))
    Next

EndFunc

Does it all make sense? Please ask if not. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Does it all make sense? Please ask if not. :unsure:

M23

Thank you for responding so quickly.

And for retaining most of what I had done previously. That really helped me to understand it.

Wish I still had my first attempt before I started brute forcing it. I'd like to see where I initially screwed up.

Again thank you. I think that completes this script. Time to think up another one.

JAFN


[size="2"]The second mouse gets the cheese[/size]

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  
Followers 0