Jump to content

Regexp in TEXT parameter of Control description


abaj
 Share

Recommended Posts

Good day,

In C++ MFC application (i'm testing it with AutoIt, ActiveX version) there are several similar dialogs with almost similar controls.

But actual "TEXT" parameter for these controls differs.

So, there might be button "TEXT:OK" in one dialog, and "TEXT:&OK" in another one.

(Of cause, this is an application problem, but workaround is needed anyway)

I might have tried it incorrectly, but following doesn't work:

ControlClick("My Window", "", "[CLASS:Button; TEXT:.*Finish; INSTANCE:2]")

Of cause i can check which of buttons "TEXT:OK" or "TEXT:&OK" exists at each specified moment of script, but it looks like slow solution.

Considering, that there are REGEXPCLASS parameter for Control definition, is there some functionality like REGEXPTEXT ?

Like

ControlClick("My Window", "", "[CLASS:Button; REGEXPTEXT:.*Finish; INSTANCE:2]")

Thanks for any comments

Link to comment
Share on other sites

No, but you could implement that pretty easily by looping on INSTANCE (1-based) and testing the text in any way you like.

Demo not tested, but you get the idea:

$sTitle = "My Window"
$sText = ""
$sClass = "Button"

$hButton = _ControlGetHandleByText($sTitle, $sText, $sClass, ".*Finish")
If @error Then
    MsgBox(16, "Error", "Not found, _ControlGetHandleByText() returned @error = " & @error)
Else
    ControlClick($sTitle, $sText, $hButton)
    MsgBox(64, "Success", "Click button with handle = " & $hButton)
EndIf

Func _ControlGetHandleByText($vWinTitle, $vWinText, $sCtrlClass, $sTextRegExp)
    Local $hWin, $hCtrl, $sCtrlText, $i = 0

    $hWin = WinGetHandle($vWinTitle, $vWinText)
    If @error Then Return SetError(1, 0, "") ; Window not found

    If Not IsString($sCtrlClass) Then Return SetError(2, 0, "") ; Invalid class string

    While 1
        $i += 1

        $hCtrl = ControlGetHandle($hWin, "", "[CLASS:" & $sCtrlClass & "; INSTANCE:" & $i & "]")
        If @error Then Return SetError(3, 0, "") ; Control not found

        If StringRegExp(ControlGetText($hWin, "", $hCtrl), $sTextRegExp, 0) Then Return $hCtrl ; Match found
    WEnd
EndFunc   ;==>_ControlGetHandleByText

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you,

I'll use your solution.

Just wanted to be sure that there is no built-in way to get control by regexp text.

Because of using AutoIt via COM as AutoItX3.dll (from C#), i was thinking that built-in way will work some faster.

But timers show that "WinGetHandle" takes about 1 ms, and "ControlGetText" takes about 0.7 ms.

So, even with 10-20 controls on the dialog - this loop will work fast enough.

Thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

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