Sign in to follow this  
Followers 0
Silverlode

Get controlID from text string?

11 posts in this topic

Hi, I've searched and not come up with much. I would like to get the controlID of a text label based on what the text is. So, if I have several labels in a WindowsForm and one of them is "This Text String", I want to get the controlID of that particular label. I haven't found a way to get that, based on the text in the control. Any ideas out there?

I appreciate it.

Share this post


Link to post
Share on other sites



More specifically I need to get the classnameNN from the text string. I did figure out to use ControlGetHandle to get the handle of the controlID, but now I need to get the classnameNN of that handle.

Share this post


Link to post
Share on other sites

More specifically I need to get the classnameNN from the text string. I did figure out to use ControlGetHandle to get the handle of the controlID, but now I need to get the classnameNN of that handle.

_WinAPI_GetClassName 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Thanks JohnOne, that returns the class, not the classnameNN.

Share this post


Link to post
Share on other sites

The classnameNN changes from machine to machine, installation to installation, for this particular dialog. I need to get the classnameNN of a particular label (the text in that label is always the same), so that I can reference another label (which has text that changes) and read its text.

Basically I'm trying to read the version number of an installed piece of software from a dialog that lists a bunch of Excel extensions.

Share this post


Link to post
Share on other sites

I actually solved this another way by creating an array from all the controls within a dialog, and sorting to find what I needed. Thanks.

Share this post


Link to post
Share on other sites
Func WinListChildren($hWnd, ByRef $avArr)
    If UBound($avArr, 0) <> 2 Then
        Local $avTmp[10][2] = [[0]]
        $avArr = $avTmp
    EndIf

    Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)

    While $hChild
        If $avArr[0][0]+1 > UBound($avArr, 1)-1 Then ReDim $avArr[$avArr[0][0]+10][2]
        $avArr[$avArr[0][0]+1][0] = $hChild
        $avArr[$avArr[0][0]+1][1] = _WinAPI_GetWindowText($hChild)
        $avArr[0][0] += 1
        WinListChildren($hChild, $avArr)
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd

    ReDim $avArr[$avArr[0][0]+1][2]
EndFunc
 
    Global $avChildren
    Local $hWinHan = ControlGetHandle("Options", "", "[CLASS:WindowsForms10.Window.8.app.0.27c59a_r77_ad1; INSTANCE:2]")
    Sleep($sm_sleep)
    WinListChildren($hWinHan, $avChildren)
    Local $vValue = "Hyperion Strategic Planning"
    Sleep($sm_sleep)
    $ArrIndex = _ArraySearch($avChildren, $vValue)
    $ArrIndexVersion = $ArrIndex - 2
    Local $iStart_Row = $ArrIndexVersion
    $VersionString = _ArrayToString($avChildren, "|", $ArrIndexVersion, $ArrIndexVersion, "-", 1, 1)

    Global $buildno = $VersionString
    Sleep($sm_sleep)
    Local $LogMsg = "INFO: Installed version is " & $buildno & "."
    _FileWriteLog(@ScriptDir & $logfile, $LogMsg)

 

Share this post


Link to post
Share on other sites

why not using [REGEXPCLASS:LABEL.*] in combination with INSTANCE:nn?

What is AU3INF or simplespy (see examples section) giving back for properties for the element you are interested in?

 

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