Sign in to follow this  
Followers 0
SmOke_N

_WinGetCtrlInfo()

12 posts in this topic

#1 ·  Posted (edited)

On a request from a user, and others I've seen lately, if you want to get the ClassNameNN or the Control ID of all the controls from a window... This should return them all in a 2 dimensional Array.

Return:
[N][0] = ClassNameNN
[N][1] = Control ID of the same control
Example:

Global $Array = _WinGetCtrlInfo(WinGetTitle(''))
Global $sOne = '[0][0] = ' & $Array[0][0] & @CR, $sTwo
For $iCC = 1 To $Array[0][0]
    $sOne &= '[' & $iCC & '][0] = ' & $Array[$iCC][0] & @CR
    $sTwo &= '[' & $iCC & '][1] = ' & $Array[$iCC][1] & @CR
Next
MsgBox(64, 'WinInfo', StringTrimRight($sOne, 1) & @CR & StringTrimRight($sTwo, 1))
Func _WinGetCtrlInfo($hWin)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    Local $sClassList = WinGetClassList($hWin), $iAdd = 1, $aDLL, $sHold
    Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
    For $iCount = $aSplitClass[0] To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop
            If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then
                $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1)
                $iAdd += 1
                ReDim $aReturn[$iAdd][2]
                $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount
                $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
                    ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount))
                If @error = 0 Then
                    $aReturn[$iAdd - 1][1] = $aDLL[0]
                Else
                    $aReturn[$iAdd - 1][1] = ''
                EndIf
            EndIf
        WEnd
    Next
    $aReturn[0][0] = $iAdd - 1
    Return $aReturn
EndFunc
Edited by SmOke_N
removed script garbble caused by code box issues, pointed out by Exit
1 person likes this

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites



ok...

ide use this for...


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

ok...

ide use this for...

You know... You responded in my other thread (EnCodeIt) asking the same silly question.. You'd use it for whatever you finally figure out you need it for.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ok...

ide use this for...

Simple, if you do not know or have a need, then you do not need it or have enough knowledge to use it. If you need help then state what help you need, otherwise read the helpfile with healthy interest and then use the support forum if you have problems with basic AutoIt use. But please do not post dribble as it can be mistaken as an insult. :)

Edit:

Nice code as always SmOke :P

Edited by MHz

Share this post


Link to post
Share on other sites

ok...

ide use this for...

@Dethredic:

You might be inclined to look at an app that uses a more precise class list than that reported by wingetclasslist. Take a look at grabber in my sig.

@SmOke_N:

Do you mind if I used this neat func in grabber? I've been meaning to update it as I had an ugly bug, but could never find the time.

I wanted to add a couple of buttons to enable grabbing controls, which was no prob as I already had the coordinates for those.

Your solution enables me to check for control text, but there's a few controls which I still need to check further for a general solution (mainly lists (boxes, view, combos, and the likes)).

IVAN

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I really like this function, but when I used it the first control wasn't showing up in the array. I found that it was being overwritten at the end of the function when $aReturn[0][0] is being set to the number of controls. To fix this $iAdd should be initialized to 1, so you get the number of controls plus 1 (for the first element of the array which is the count). Therefore, if you have 17 controls then your array is 18 long, the first element (0) is the count, and each control is an element that follows. I have posted the updated function below.

Func _WinGetCtrlInfo($hWin)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    $iAdd = 1
    Local $sClassList = WinGetClassList($hWin), $iAdd, $aDLL, $sHold
    Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
    For $iCount = $aSplitClass[0] To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop
            If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then
                $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1)
                $iAdd += 1
                ReDim $aReturn[$iAdd][2]
                $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount
                $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
                    ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount))
                If @error = 0 Then
                    $aReturn[$iAdd - 1][1] = $aDLL[0]
                Else
                    $aReturn[$iAdd - 1][1] = ''
                EndIf
            EndIf
        WEnd
    Next
    $aReturn[0][0] = $iAdd - 1
    Return $aReturn
EndFunc
Edited by eliboy

Share this post


Link to post
Share on other sites

I really like this function, but when I used it the first control wasn't showing up in the array. I found that it was being overwritten at the end of the function when $aReturn[0][0] is being set to the number of controls. To fix this $iAdd should be initialized to 1, so you get the number of controls plus 1 (for the first element of the array which is the count). Therefore, if you have 17 controls then your array is 18 long, the first element (0) is the count, and each control is an element that follows. I have posted the updated function below.

Func _WinGetCtrlInfo($hWin)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    $iAdd = 1
    Local $sClassList = WinGetClassList($hWin), $iAdd, $aDLL, $sHold
    Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
    For $iCount = $aSplitClass[0] To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop
            If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then
                $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1)
                $iAdd += 1
                ReDim $aReturn[$iAdd][2]
                $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount
                $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
                    ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount))
                If @error = 0 Then
                    $aReturn[$iAdd - 1][1] = $aDLL[0]
                Else
                    $aReturn[$iAdd - 1][1] = ''
                EndIf
            EndIf
        WEnd
    Next
    $aReturn[0][0] = $iAdd - 1
    Return $aReturn
EndFunc
Nice catch....

I'll update the first post...


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks a lot Smoke_N! I was looking for something like this. :mellow:

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks a lot Smoke_N! I was looking for something like this. :mellow:

This and a lot of other great hits from Smoke are in "Autoit Wrappers"

... Think I will change the name to "SmOke_N's Wrappers"

lol

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

This and a lot of other great hits from Smoke are in "Autoit Wrappers"

... Think I will change the name to "SmOke_N's Wrappers"

lol

8)

Yeah Smoke_N and you both have helped me with a few things. :mellow:

I haven't ever tried the Autoit Wrappers. i'm gonna check it out too.

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