Sign in to follow this  
Followers 0
RogerH

ControlClick() just not interacting with Dialog

13 posts in this topic

Let's start with the code

#include <array.au3>
#include <GuiComboBox.au3>
#RequireAdmin


Func _WinWaitActivate($title, $text, $timeout = 5)
WinWait($title, $text, $timeout)
If Not WinActive($title, $text) Then WinActivate($title, $text)
If Not WinWaitActive($title, $text, 5) Then
  Return 0
Else
  Return 1
EndIf
EndFunc   ;==>_WinWaitActivate


_WinWaitActivate("Dexterity Runtime","")
ControlClick("Dexterity Runtime","","[CLASS:Button; INSTANCE:1]")

No matter how hidden I make the "Dexterity Runtime" window, _WinWaitActivate does great finding it and bringing it to the forefront.

ControlClick("Dexterity Runtime","","Button1") didn't help

I also tried several MouseClick variants as well, but no matter what I've tried this window just won't click off.

Here's the relevant WindowInfo output:

>>>> Window <<<<
Title: Dexterity Runtime
Class: TNTDLG
Position: 717, 320
Size: 486, 200
Style: 0x94C00000
ExStyle: 0x00000101
Handle: 0x00000000001E1280


>>>> Control <<<<
Class: Button
Instance: 1
ClassnameNN: Button1
Name: 
Advanced (Class): [CLASS:Button; INSTANCE:1]
ID: 1
Text: OK
Position: 200, 132
Size: 80, 24
ControlClick Coords: 52, 12
Style: 0x5000030B
ExStyle: 0x00000000
Handle: 0x00000000002211F8


>>>> Mouse <<<<
Position: 972, 489
Cursor ID: 0
Color: 0xDDDDDD


>>>> StatusBar <<<<


>>>> ToolsBar <<<<


>>>> Visible Text <<<<
OK




>>>> Hidden Text <<<<

This is my third go-round with this, and I am just at a loss as to why it isn't working.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this out, paste back the consolewrites, that will help us find the failure point

#include <array.au3>
#include <GuiComboBox.au3>
#RequireAdmin

Func _WinWaitActivate($title, $text, $timeout = 5)
    $hReturn = WinWait($title, $text, $timeout)
    If Not IsHWnd($hReturn) Then Return False
    If Not WinActive($hReturn) Then WinActivate($hReturn)
    If WinWaitActive($hReturn, "", $timeout) Then
        Return $hReturn
    Else
        Return False
    EndIf
EndFunc   ;==>_WinWaitActivate

ConsoleWrite("Starting" & @crlf)
$hwnd = _WinWaitActivate("Dexterity Runtime", "")
If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
$hControl = ControlGetHandle($hwnd, "", 1)
If IsHWnd($hControl) Then
    $bFocus     = ControlFocus($hwnd,"",$hControl)
    $bVisible   = ControlCommand($hwnd,"",$hControl,"IsVisible", "")
    $bEnabled   = ControlCommand($hwnd,"",$hControl,"IsEnabled", "")
    ConsoleWrite("Able to find button; $bFocus=[" & $bFocus & "], $bVisible=[" & $bVisible & "], $bEnabled=[" & $bEnabled & "]." & @CRLF)

Else
    ConsoleWrite("Unable to focus on button" & @CRLF)
    Exit 2
EndIf
If ControlClick($hwnd,"",$hControl) Then
    ConsoleWrite("Able to click button" & @CRLF)
Else
    ConsoleWrite("Unable to click button" & @CRLF)
    Exit 3
EndIf
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

 

Try this out, paste back the consolewrites, that will help us find the failure point

 

Took me a bit to figure out that to see the console writes, SciTE had to be running as admin too :S

 

Starting
Able to find window
Able to find button
Able to click button
 
But... it lies... the button remains unclicked.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

try again with this, and we will verify you are grabbing the proper control:

#include <array.au3>

#include <WinAPI.au3>
#include <GuiComboBox.au3>
#RequireAdmin
Func Var_GetAllWindowsControls2($hCallersWindow)
    $sClassList = WinGetClassList($hCallersWindow)
    $aClassList = StringSplit($sClassList, @CRLF, 2)
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)
    $iCurrentClass = ""
    $iCurrentCount = 1
    $iTotalCounter = 1
    For $i = 0 To UBound($aClassList) - 1
        If $aClassList[$i] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$i]
            $iCurrentCount = 1
        EndIf
        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aPos = ControlGetPos($hCallersWindow, "", $hControl)
        $sControlID = _WinAPI_GetDlgCtrlID($hControl)
        If IsArray($aPos) Then
            ConsoleWrite("   Func=[Var_GetAllWindowsControls]: ControlCounter=[" & $iTotalCounter & "] ControlID=[" & $sControlID & "] Handle=[" & $hControl & "] ClassNN=[" & $iCurrentClass & $iCurrentCount & "] XPos=[" & $aPos[0] & "] YPos=[" & $aPos[1] & "] Width=[" & $aPos[2] & "] Height=[" & $aPos[3] & "] Text=[" & $text & "]." & @CRLF)
        EndIf
        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next
EndFunc   ;==>Var_GetAllWindowsControls2

Func _WinWaitActivate($title, $text, $timeout = 5)
    $hReturn = WinWait($title, $text, $timeout)
    If Not IsHWnd($hReturn) Then Return False
    If Not WinActive($hReturn) Then WinActivate($hReturn)
    If WinWaitActive($hReturn, "", $timeout) Then
        Return $hReturn
    Else
        Return False
    EndIf
EndFunc   ;==>_WinWaitActivate

ConsoleWrite("Starting" & @crlf)
$hwnd = _WinWaitActivate("AutoIt Help", "")

If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
Var_GetAllWindowsControls2($hwnd)
$hControl = ControlGetHandle($hwnd, "", 1)
If IsHWnd($hControl) Then
    $bFocus     = ControlFocus($hwnd,"",$hControl)
    $bVisible   = ControlCommand($hwnd,"",$hControl,"IsVisible", "")
    $bEnabled   = ControlCommand($hwnd,"",$hControl,"IsEnabled", "")
    $aPos       = ControlGetPos($hwnd,"",$hControl)
    ConsoleWrite("Able to find button; $bFocus=[" & $bFocus & "], $bVisible=[" & $bVisible & "], $bEnabled=[" & $bEnabled & "], x=[" & $aPos[0] & "], y=[" & $aPos[1] & "], width=[" & $aPos[2] & "], height=[" & $aPos[3] & "]." & @CRLF)
Else
    ConsoleWrite("Unable to focus on button" & @CRLF)
    Exit 2
EndIf
If ControlClick($hwnd,"",$hControl) Then
    ConsoleWrite("Able to click button" & @CRLF)
Else
    ConsoleWrite("Unable to click button" & @CRLF)
    Exit 3
EndIf
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Starting
Able to find window
   Func=[Var_GetAllWindowsControls]: ControlCounter=[1] ControlID=[1] Handle=[0x0000000000341158] ClassNN=[button1] XPos=[200] YPos=[132] Width=[80] Height=[24] Text=[OK].
Able to find button; $bFocus=[0], $bVisible=[1], $bEnabled=[1], x=[200], y=[132], width=[80], height=[24].
Able to click button
 
Yet there the window still sits... mocking me :)
Edited by RogerH

Share this post


Link to post
Share on other sites

Ouch; definatly on the proper control.  Not sure what's up...odd that the bFocus is 0...maybe the window state is not valid...add this after your function (if the window is enabled, then i'm out of ideas)

ConsoleWrite("Starting" & @crlf)
$hwnd = _WinWaitActivate("AutoIt Help", "")
If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

So here's my current tester... I launch the installer manually, and when it gets to my annoying popup point: 

#include <array.au3>
#include <WinAPI.au3>
#RequireAdmin




Func _ClickWait($title, $text, $control, $timeout = "")
If WinWait($title, $text, $timeout) Then
ControlClick ($title, $text, $control)
EndIf
EndFunc


Func _WinWaitActivate($title, $text, $timeout = 5)
WinWait($title, $text, $timeout)
If Not WinActive($title, $text) Then WinActivate($title, $text)
If Not WinWaitActive($title, $text, 5) Then
  Return 0
Else
  Return 1
EndIf
EndFunc   ;==>_WinWaitActivate


_ClickWait("Dexterity Runtime","OK",120,1) ;this is the part giving me hell -- right now we manually have to click this off


ConsoleWrite("Starting" & @crlf)
$hwnd = _WinWaitActivate("Dexterity Runtime", "OK")
If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)

I launch this and here are my console results:

 
Starting
Unable to find window
 
Which is extra strange because it pulled the window out to the forefront -- attaching screenies
 
post-58145-0-24969600-1371506732_thumb.ppost-58145-0-98394500-1371506742_thumb.p
 
[EDIT: More] Some digging suggests that I'm not pulling the window handle from the WinWaitActivate here --- will tweak.
Edited by RogerH

Share this post


Link to post
Share on other sites

#include <array.au3>
#include <WinAPI.au3>
#RequireAdmin


Func _ClickWait($title, $text, $control, $timeout = "")
    If WinWait($title, $text, $timeout) Then
        ControlClick ($title, $text, $control)
    EndIf
EndFunc




ConsoleWrite("Starting" & @crlf)
$hwnd = WinWait("Dexterity Runtime", "OK")
If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)
WinActivate ("Dexterity Runtime","OK")
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)
_ClickWait("Dexterity Runtime","OK",120,1)
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)

Starting
Able to find window
$iWinState=[7]
$iWinState=[15]
$iWinState=[15]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <array.au3>
#include <WinAPI.au3>
#RequireAdmin


Func _ClickWait($title, $text, $control, $timeout = "")
    If WinWait($title, $text, $timeout) Then
        ControlClick ($title, $text, $control)
    EndIf
EndFunc


$mouseStart = WinGetPos ("Dexterity Runtime","OK")



ConsoleWrite("Starting" & @crlf)
ConsoleWrite($mouseStart[0] & "," & $mouseStart[1] & @crlf)

$hwnd = WinWait("Dexterity Runtime", "OK")
If IsHWnd($hwnd) Then
    ConsoleWrite("Able to find window" & @CRLF)
Else
    ConsoleWrite("Unable to find window" & @CRLF)
    Exit 1
EndIf
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)
WinActivate ("Dexterity Runtime","OK")
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)
;ClickWait("Dexterity Runtime","OK",120,1)
MouseMove($mouseStart[0] + 240, $mouseStart[1] + 144)
MouseClick("left")
$iWinState = WinGetState($hwnd)
ConsoleWrite("$iWinState=[" & $iWinState & "]" & @CRLF)

Making it even uglier... manual mouse move (which I can't see happen... my cursor does not move)

[EDIT] Forgot to turn on absolute mouse coord mode... tried that again... no luck

Edited by RogerH

Share this post


Link to post
Share on other sites

you mixed up the id with the timeout:

_ClickWait("Dexterity Runtime","OK",120,1)
 

change to

_ClickWait("Dexterity Runtime","OK",1,120)
 


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Been through too many variants on that today :)

No dice... same thing

Starting
717,320
Able to find window
$iWinState=[7]
$iWinState=[15]
$iWinState=[15]
 
the full output

Share this post


Link to post
Share on other sites

Retried with every variant I could think of:

Text, No Text, Control ID, Advanced Mode, ClassnameNN.... none of the three worked, nor did the directive to click the mouse.

Thoughts on why I wouldn't see the cursor move?

Share this post


Link to post
Share on other sites

Not all windows accept controlclicks or mouse clicks this i let you know. You can get all informations you want from the window but unfortunatly nor mouse moves will work on it.
An other way is a memory click but i don't think it is worth. More trouble than worth it.

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