Jump to content

problem with $aArray = WinList()


Burgaud
 Share

Recommended Posts

Here is my code:

#include <Array.au3>
#include <Process.au3>
#include <WinAPIProc.au3>
while 1
        local $aArray = WinList()
        ;$aArray[0][0] = Number of windows returned
        ;$aArray[1][0] = 1st window title
        ;$aArray[1][1] = 1st window handle (HWND)
        for $i = 1 to $aArray[0][0]
                $aArray[$i][2] = WinGetState($aArray[$i][1])
        next
        _ArrayDisplay($aArray"WinList")
 
wend

 

 

Obviously, the line $aArray[$i][2] = WinGetState($aArray[$i][1]) does not work.

Why?

I am very weak with Autoit's array. And from my "weak" understanding of the above is that, $aArray is not an actual array because of the way it was created and filled? And if so, how can I resolve the above?

Should I create a real array local $Array[x][y] and _ArrayAdd ($Array, ...)  into it in the for loop?

 

Link to comment
Share on other sites

1 hour ago, Burgaud said:

Obviously, the line $aArray[$i][2] = WinGetState($aArray[$i][1]) does not work.

Why?

Because the array created by WinList has 2 columns (Title & Hwnd).  You attempted to place a value (Window state) in a non-existent 3rd column.  One way to do what you are trying to do is to add a 3rd column to the array by using ReDim and then add your window states.

#include <Array.au3>
#include <Process.au3>
#include <WinAPIProc.au3>

Global $aArray = WinList()

;$aArray[0][0] = Number of windows returned
;$aArray[1][0] = 1st window title
;$aArray[1][1] = 1st window handle (HWND)

ReDim $aArray[UBound($aArray)][3] ;Add 3rd column to the WinList array

For $i = 1 To $aArray[0][0]
    $aArray[$i][2] = WinGetState($aArray[$i][1])
Next

_ArrayDisplay($aArray, "WinList", "", 0, Default, "Title|Hwnd|State")

 

Edited by TheXman
Link to comment
Share on other sites

  • 3 weeks later...

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
 Share

  • Recently Browsing   0 members

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