Jump to content
Sign in to follow this  
gmartinezsan

How to iterate all the controls in a form

Recommended Posts

#include <WinAPI.au3>
#include <Array.au3>


Global $vChildWindwos = 0

HotKeySet("{F1}", "GetAllCtrls")
HotKeySet("{ESC}", "Terminate")


While 1
WEnd

Func GetAllCtrls()

$HWND = WinGetHandle(("[ACTIVE]"))
$vChildWindwos = GetChildWindows($HWND)

if IsArray($vChildWindwos) Then

ReDim $vChildWindwos[UBound($vChildWindwos)][14]

For $i = 0 To (UBound($vChildWindwos) - 1)

$Handle = ControlGetHandle ($HWND,"",$vChildWindwos[$i][2])
$Pos = ControlGetPos ($HWND,"",$vChildWindwos[$i][2])

$vChildWindwos[$i][7] = $Handle
$vChildWindwos[$i][8] = $vChildWindwos[$i][1]
$vChildWindwos[$i][9] = $vChildWindwos[$i][2]
$vChildWindwos[$i][10] = $Pos[0]
$vChildWindwos[$i][11] = $Pos[1]
$vChildWindwos[$i][12] = $Pos[2]
$vChildWindwos[$i][13] = $Pos[3]

Next

_ArrayDisplay($vChildWindwos, "")

EndIf

EndFunc

Func Terminate()
    Exit
EndFunc


Func GetChildWindows($HWND)
$vChildWindwos = 0
$RegChildProc = DLLCallbackRegister("EnumChildProc","BOOL","HWND;LPARAM")
$ChildProcPtr = DllCallbackGetPtr($RegChildProc)
DllCall("user32.dll","BOOL","EnumChildWindows","HWND",$HWND,"PTR",$ChildProcPtr,"LPARAM",$HWND)
DllCallbackFree($RegChildProc)
Return $vChildWindwos
EndFunc

Func EnumChildProc($HWND,$lParam)

Local $EndTest = False

For $i = 0 To UBound($vChildWindwos) - 1
if $HWND = $vChildWindwos[$i][0] Then $EndTest = True
Next

if $EndTest = False Then
if Not IsArray($vChildWindwos) Then
Dim $vChildWindwos[1][7]
Else
ReDim $vChildWindwos[UBound($vChildWindwos) + 1][7]
EndIf

$Rect = _WinAPI_GetWindowRect($HWND)
$Left = DllStructGetData($Rect,1)
$Top = DllStructGetData($Rect,2)
$Right = DllStructGetData($Rect,3)
$Bottom = DllStructGetData($Rect,4)

$W =  $Right - $Left
$H = $Bottom - $Top

_WinAPI_ScreenToClient($lParam,$Rect)
$L = DllStructGetData($Rect,1)
$T = DllStructGetData($Rect,2)

$ClassName = _WinAPI_GetClassName($HWND)
$vChildWindwos[UBound($vChildWindwos) - 1][0] = $HWND
$vChildWindwos[UBound($vChildWindwos) - 1][1] = $ClassName

$INSTANCE = 0
For $j = 0 To (UBound($vChildWindwos) - 1)
if $ClassName == $vChildWindwos[$j][1] Then $INSTANCE += 1
Next

$vChildWindwos[UBound($vChildWindwos) - 1][2] = "[CLASS:" & $ClassName & "; INSTANCE:" & $INSTANCE & "]"
$vChildWindwos[UBound($vChildWindwos) - 1][3] = $L
$vChildWindwos[UBound($vChildWindwos) - 1][4] = $T
$vChildWindwos[UBound($vChildWindwos) - 1][5] = $W
$vChildWindwos[UBound($vChildWindwos) - 1][6] = $H

Return True

Else

Return False

EndIf

EndFunc

Edited by wolf9228

صرح السماء كان هنا

 

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  

×
×
  • Create New...