Sign in to follow this  
Followers 0
DrJeseuss

Trouble controlling another window

6 posts in this topic

#1 ·  Posted (edited)

I'm trying to control another app by adjusting sliders and clicking buttons. Here's the details of one of the buttons:

>>>> Window <<<<
Title:
Class: ThunderRT6FormDC
Position: 1, -3
Size: 733, 564
Style: 0x16020000
ExStyle: 0x00040000
Handle: 0x004B08FC
>>>> Control <<<<
Class: ThunderRT6UserControlDC
Instance: 47
ClassnameNN: ThunderRT6UserControlDC47
Name:
Advanced (Class): [CLASS:ThunderRT6UserControlDC; INSTANCE:47]
ID:
Text:
Position: 474, 299
Size: 105, 18
ControlClick Coords: 84, 10
Style: 0x56000000
ExStyle: 0x00000000
Handle: 0x00490A30

I have verified I can control the window:

If WinActive("[CLASS:ThunderRT6FormDC]") Then
  ConsoleWrite("Window was active" & @CRLF)
Else
  ConsoleWrite("Window was not active" & @CRLF)
EndIf

However, when attempting to click a button I get no response:

ControlClick("[CLASS:ThunderRT6FormDC]", "", "CLASS:ThunderRT6UserControlDC; INSTANCE:47")

or

ControlClick("[CLASS:ThunderRT6FormDC]", "", "ClassnameNN:ThunderRT6UserControlDC47")

I've also tried preceding those commands with:

WinActivate("[CLASS:ThunderRT6FormDC]")

This yielded no change. Any suggestions?? Does this appear to be an issue with my code or the app? As a last resort, any other ways of control aside from these Controlxxx commands? (not 'mouse emulation' please.) :D

Edited by DrJeseuss

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Have you tried ControlSend and send "{ENTER}" or "{SPACE}"? Sometimes that is easier than clicking and it still gives you the same level of control.

Edit: Send "{APPSKEY}" if emulating a mouse right-click

Edited by Varian

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I've tried tis suggestion and it appears this also is not working. I did a bit of 'error checking' and it appears I'm not getting focus to the controls:

WinActivate("[CLASS:ThunderRT6FormDC]")
sleep(200)
ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[ClassnameNN:ThunderRT6CheckBox15]")  ; Checkbox
$a = ControlGetFocus("[CLASS:ThunderRT6FormDC]")
ConsoleWrite("Focus: " & $a & @CRLF)
ControlSend("[CLASS:ThunderRT6FormDC]", "", "[ClassnameNN:ThunderRT6CheckBox15]", "{+}")
ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[ClassnameNN:ThunderRT6UserControlDC3]")   ; Slider that adjusts with up or down arrow when in focus
$a = ControlGetFocus("[CLASS:ThunderRT6FormDC]")
ConsoleWrite("Focus: " & $a & @CRLF)
ControlSend("[CLASS:ThunderRT6FormDC]", "", "[ClassnameNN:ThunderRT6UserControlDC3]", "{DOWN}")
sleep(200)

Both of my ControlGetFocus commands return the same value, and not the control I've requested (15 and 3 as above). It instead reports both as the last control I clicked manually before running the script. Any ida why these aren't getting focus or commands?

Just did more checking. here's the code:

$a = ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[ClassNameNN:ThunderRT6CheckBox15]")  ; Failure returns 0
ConsoleWrite("ControlFocus?: " & $a & @CRLF)
$a = ControlGetFocus("[CLASS:ThunderRT6FormDC]")
ConsoleWrite("Focus: " & $a & @CRLF)
$a = ControlSend("[CLASS:ThunderRT6FormDC]", "", "[ClassnameNN:ThunderRT6CheckBox15]", "{+}")  ; Failure returns 0 if window/control is not found.
ConsoleWrite("ControlSend?: " & $a & @CRLF)

And the response.

ControlFocus?: 0
Focus: ThunderRT6CheckBox15
ControlSend?: 0

It appears to be failing to find the control. Is there something I'm missing here?

(Note: I manually set focus to the control in the above demonstration. If manually clicking a different control, it's ClassNameNN is shown instead. I chose this one to match with my code to verify correct naming, syntax, etc.)

Edited by DrJeseuss

Share this post


Link to post
Share on other sites

I have success... somewhat... Hee's my code:

WinActivate("[CLASS:ThunderRT6FormDC]")
ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6UserControlDC44]")
ControlSend("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6UserControlDC44]", "{SPACE}")
ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6CheckBox15]")
ControlSend("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6CheckBox15]", "{SPACE}")
ControlFocus("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6UserControlDC3]")
ControlSend("[CLASS:ThunderRT6FormDC]", "", "[CLASSNN:ThunderRT6UserControlDC3]", "{DOWN}")

I had a syntax problem before. Now my issue is that I must have focus on the control and simulate key presses... which means an active GUI. I can hide it, though each time I press a button to change pages the GUI reappears. I can rehide, but this makes for a lot of flashing. Any ideas?

Share this post


Link to post
Share on other sites

Can you still interact with your controls if the window is moved out of the viewable screen? You can "restore" it when you are finished messing with your controls. Here is an example:

Run('calc.exe')
WinWait('[CLASS:CalcFrame]')
$wPos = WinGetPos('[CLASS:CalcFrame]')
Local $x = $wPos[0], $y = $wPos[1]
While 1
WinMove('[CLASS:CalcFrame]', '', $x, $y)
If $x < @DesktopWidth + 10 Then $x += 5
If $y < @DesktopHeight + 10 Then $y += 5
If ($x >= @DesktopWidth + 10) And ($y >= @DesktopHeight + 10) Then ExitLoop
Sleep(2)
WEnd
ControlSend('[CLASS:CalcFrame]', '', '[CLASS:#32770; INSTANCE:1]', @YEAR)
Sleep(1000)
WinMove('[CLASS:CalcFrame]', '', $wPos[0], $wPos[1])

Share this post


Link to post
Share on other sites

Varian,

Moving off the screen did allow me to continue with control of the app. I'll have to make this work for now until I can bang on this some more to try getting a bit more direct control of the app. Thanks for the suggestions!!

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