Sign in to follow this  
Followers 0
krpandrei

Rearrange Windows

3 posts in this topic

I made this script to search for all open/visible windows with title which contains string ATHENA and put them into an array and after that arrange those windows side by side.

My problem is that I also whant at the end to delete the arrays completely.I have searched the forum , tried examples but I didn't managed to empty/delete the arrays.

#include <Array.au3>


Global $GUIVersion = "0.0"
Global $GUITitle = "Athena Windows Rearrange v" & $GUIVersion

Global $HandlesArray[1]
Global $TitlesArray[1]

$W=@DesktopWidth/2
$H=@DesktopHeight-25

Local $Paused
HotKeySet("{PAUSE}", "_TogglePause")
HotKeySet("{ESC}", "_Terminate")

#Region ### START Koda GUI section ### Form=g:\script\positons final\gui.kxf
;~ $GUI = GUICreate($GUITitle, 400, 400, -1, -1)
;~ GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_CreateArrays()

$rows = UBound($TitlesArray)-1
    If $rows = 0 Then
        $msgtext = "Could not find any open ATHENA projects" & @CRLF & "Please open some for me !"
        MsgBox ( 0, "Error", $msgtext)
    ElseIf $rows = 1 Then
        MsgBox(0, "Error", "I found just one ATHENA window" & @CRLF & "Nothing to do !")
    Else
        _RearangeWindows()
        ;_Delete ($TitlesArray)
        ;_Delete ($HandlesArray)

    EndIf

Func _CreateArrays()
    
    $var = WinList()
        For $i = 1 to $var[0][0]
            ; Only display visble windows that have a title
            If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                $nOffset = 1 ;Option 1, using offset
                $asResult=StringRegExp($var[$i][0], "ATHENA", 1, $nOffset)          ; Search windows titles that contains "ATHENA" sting
                    If @error = 0 Then
                        _ArrayAdd($HandlesArray, $var[$i][1])                       ; array with only "Athena" -handels- 
                        _ArrayAdd($TitlesArray, $var[$i][0])                        ; array with only "Athena" -title names-
                    ;Else
                        ;ExitLoop
                    EndIf
            EndIf
        Next
;~  _ArrayDisplay($HandlesArray, "Array: ATHENA handles")
;~  _ArrayDisplay($TitlesArray, "Array: ATHENA titles")

EndFunc ;==> Create arrays for existing Athena windows

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc ;==> Checkes window state is visible

Func _RearangeWindows()
    $WindowsNumber = UBound($TitlesArray)-1                         ;total windows number in Titels Array
    For $i=1 to $WindowsNumber
        If Mod($i, 2) <> 0 Then                                     ;check if a number is even or not
            WinMove ($HandlesArray[$i], "",0 ,0 , $W, $H)
        Else
            WinMove ($HandlesArray[$i], "", @DesktopWidth/2, 0, $W, $H)
        EndIf
    Next
EndFunc ;==> Arange windows side by side

Func _TogglePause ()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip($GUITitle & ' is "Paused"',@DesktopHeight/2,@DesktopWidth/2, "", 0, 2)
    WEnd
    ToolTip("")
EndFunc ;==> TogglePause

Func _Terminate ()
    MsgBox(0, $GUITitle, "Exit!")
    Exit 0
EndFunc ;==> Terminate

This is what I tried

_Delete ($TitlesArray)
_Delete ($HandlesArray)

Func _Delete ($aArray)

For $i = 1 To Ubound($aArray)-1

    _ArrayDelete($aArray, 0) ; Always the first element until $aArray = "" or nothing.
Next
;_ArrayDisplay($aArray, "Array after delete")
EndFunc

Share this post


Link to post
Share on other sites



krpandrei,

It is even easier than NerdFencer thinks! :D From the Help file:

"To erase an array (maybe because it is a large global array and you want to free the memory), simply assign a single value to it:

$array = 0

This will free the array and convert it back to the single value of 0"

No need for ReDim or assigning a valuesto an element.

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

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