Jump to content

ControlGetHandle not matching on regex?


cag8f
 Share

Go to solution Solved by ioa747,

Recommended Posts

Hi all.  I'm having issues understanding a regular expression when used with ControlGetHandle.  If I call ControlGetHandle and pass it a string value for the third parameter, it returns a valid ID (0x00150BE8).  But if I change that parameter from a string to a regular expression that I think should match, the function returns an invalid ID and an error code 1.  What am I misunderstanding?

My code is below.

$cWnd = WinWait("ShareX - Color picker", "", 3)
ControlClick($cWnd, '', ControlGetHandle($cWnd, "", 'WindowsForms10.BUTTON.app.0.1a52015_r6_ad14'))
ControlGetHandle($cWnd, "", 'WindowsForms10.BUTTON.app.0.1a52015_r6_ad142'); Returns: 0x00150BE8
;~ ControlGetHandle($cWnd, "", '[REGEXPCLASS:^WindowsForms10\.BUTTON\.app\.0\.1a52015_r6_ad142$]'); Returns: 0x00000000 (error code 1)

 

 

Link to comment
Share on other sites

  • Solution

couldn't find which button that is the WindowsForms10.BUTTON.app.0.1a52015_r6_ad142
but i made an example with the button pick color from screen

$hWnd = WinWait("ShareX - Color picker", "", 3)
ConsoleWrite("$hWnd=" & $hWnd & @CRLF)

;pick color from screen
$hPickColorFromScreen = ControlGetHandle($hWnd, "", '[REGEXPCLASS:WindowsForms10\.BUTTON\.app\.0\..+_r\d+_ad1; INSTANCE:36]')
ConsoleWrite("$hPickColorFromScreen=" & $hPickColorFromScreen & @CRLF)
ControlClick($hWnd, '', $hPickColorFromScreen)

ControlGetHandle($hWnd, "", "[REGEXPCLASS:<>; INSTANCE:<>]")

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

@ioa747 @Nine Thanks for that.  Using CLASS instead of CLASSNAMENN, and adding the INSTANCE, resolved my issue. Thanks very much.  But what about the value for instance?  In my case it is `42` which I've hardcoded.  What if that changes in the future?  Can I use a regex pattern to match on it in my code?  Or maybe it is something that shouldn't change very often?

Link to comment
Share on other sites

@Nine how can catch   with regex pattern, e.g. one click on the control

0x001D0E6A WindowsForms10.BUTTON.app.0.1a52015 _r22_ad1      20        1904234

so as not to catch any of the rest, without the use of INSTANCE ?

230910-162547-899_AutoIt3_uEyH7.png.9015cd8585eb4e64d30f87b952409ce8.png

 

$hWnd = WinWait("ShareX - Color picker", "", 3)
ConsoleWrite("$hWnd=" & $hWnd & @CRLF)

;pick color from screen    WindowsForms10.BUTTON.app.0.1a52015 _r22_ad1
$hPickColorFromScreen = ControlGetHandle($hWnd, "", '[REGEXPCLASS:WindowsForms10\.BUTTON\.app\.0\..+_r\d+_ad1; INSTANCE:20]')
ConsoleWrite("$hPickColorFromScreen=" & $hPickColorFromScreen & @CRLF)
ControlClick($hWnd, '', $hPickColorFromScreen)

 

Edit:
or this is a  need case ?

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • 2 weeks later...
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...