Sign in to follow this  
Followers 0
cat_named_dog

udf to list control id's of a window

9 posts in this topic

hi,

does anybody know how to list the control's on a window ( not au3 gui )?

if possible, i would love a function that would return the control id's by specifying the hwnd. i can at present only list the classes of a window, which doesnt really help me, or i do not know how to move that extra step forward..

any help would be greatly appreciated.

thanks.

Share this post


Link to post
Share on other sites



WinGetClassList() ... I've written a few functions to return the actuall ClassNameNN and or Control ID using that function... you could do a search for that + my username.


[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

hi,

thanks for your reply.

i have used the WinGetClassList() function to get the class list in my code, but like other users on the forum it returns only the classname, not the control's name.. if you follow.. i see your examples use the position of a control to get the name, but my application needs to display a list of controls by name, which a user assigns to various functions. as the target window is not static, ie. controls move around, i cannot use location to find a specific control.

i also read that you can try get the name by appending an incremental number to the classname. ie. if your output from WinGetClassList is:

button

button

button

then the controls that exist would be called:

button1

button2

button3

now, one question i have is, will this always be the case? will the first of any class be class1? the second class2?

thanks again.

Share this post


Link to post
Share on other sites

I didn't send you to my functions to use them specifically, if you look closely at the functions, I've already done all of the adding the correct number to the controls, gave options of returning control ID's and handles as well. Don't let the functions original purpose stop you from dissecting it and using the bits and pieces you need specifically.


[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

then the controls that exist would be called:

button1

button2

button3

now, one question i have is, will this always be the case? will the first of any class be class1? the second class2?

thanks again.

Those are ClassnameNN's. They are normally consistant and can be optained by manually using AutoIt Info Tool. Position is not a problem when working with controls directly. You do not need to go to the moon and back unless it is needed and so far you have not explained a need.

Share this post


Link to post
Share on other sites

Here's me tearing one of mine apart (haven't checked for accuracy)

$Array_WinClassNameNN = _WinGetCtrlInfo(WinGetTitle(''))
For $i = 1 To UBound($Array_WinClassNameNN) - 1
    MsgBox(0, 'Control Number: ' & $i, $Array_WinClassNameNN[$i])
Next

Func _WinGetCtrlInfo($hWin)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    Local $sClassList = WinGetClassList($hWin)
    Local $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $sReturn
    For $iCount = UBound($sSplitClass) - 1 To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            If ControlGetHandle($hWin, '', $sSplitClass[$iCount] & $nCount) = '' Then ExitLoop
            If Not StringInStr(Chr(1) & $sReturn, Chr(1) & $sSplitClass[$iCount] & $nCount & Chr(1)) Then
                $sReturn &= $sSplitClass[$iCount] & $nCount & Chr(1)
            EndIf
        WEnd
    Next
    Return StringSplit(StringTrimRight($sReturn, 1), Chr(1))
EndFunc


[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

i probably am not explaining the need correctly, apologies.

first, the script i need to write is to be compiled and distributed across various machines, and on these machines autoit will not be installed, and the info viewer will not be available.

second, the software being automated will differ across versions. think office, windows, or instant messengers. on each of these, certain buttons would do the same thing, but are located in different places, and will be called different names.

the user needs to be presented a list of controls available on the window, which they will then map to the specific function performed.

so for this, i need to be able to find the available controls on a window, with their names and / or id's, regardless of their position on the window, and without using the info viewer.

thanks for your help so far.

Share this post


Link to post
Share on other sites

thanks SmOke_N, replied before inbetween yours and mhz's replies.

i have a few threads to follow now. thanks for your help.

Share this post


Link to post
Share on other sites

thanks SmOke_N, replied before inbetween yours and mhz's replies.

i have a few threads to follow now. thanks for your help.

No problem... Here's taking it one step further... returning a 2 dimensional array... [N][0] will have the ClassNameNN of the Control and [N][1] will have the Control ID of the same control.
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, $aDLL, $sHold
    Local $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
    For $iCount = UBound($sSplitClass) - 1 To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            If ControlGetHandle($hWin, '', $sSplitClass[$iCount] & $nCount) = '' Then ExitLoop
            If Not StringInStr(Chr(1) & $sHold, Chr(1) & $sSplitClass[$iCount] & $nCount & Chr(1)) Then
                $sHold &= $sSplitClass[$iCount] & $nCount & Chr(1)
                $iAdd += 1
                ReDim $aReturn[$iAdd][2]
                $aReturn[$iAdd - 1][0] = $sSplitClass[$iCount] & $nCount
                $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
                    ControlGetHandle($hWin, '', $sSplitClass[$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

[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

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