Jump to content
Eusch

Control click in dialog not working

Recommended Posts

Eusch

I want to click a control in a window. It is my own application. It's mdi base. So the hiearchy of windows is:

mdi parent window - mdi client area - mdichild window - dialog window - control to click

How I use controlclick() to click a button?

Share this post


Link to post
Share on other sites
JLogan3o13

@Eusch "not working" doesn't exactly help us help you. What does the AutoIt Window Info Tool show when you hover over the control?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Eusch

Not working: nothing happens, when I click the button manually it should switch the display. This is the script:

start_program()
lesgevers()
test()
Func start_program()

    Run( "f:\werk\plan\output\mijnplandebug.exe" )

    WinWaitActive("[CLASS:mijnplan]")
    
EndFunc
Func lesgevers()
    ; gebruik geen alt+key combinaties want die zijn taal afhankelijk
    Send("{ALT}{RIGHT}{DOWN}{DONW}{DOWN}{DOWN}{ENTER}")
    ; todo titels zijn taalafhankelijk
    WinWaitActive("MijnPlan","Lesgevers")
EndFUnc
Func test()
    ControlClick ("[CLASS:mymdichild]", "Add", 101, "left", 1)
    winclose("[CLASS:mymdichild]")
EndFunc

Info tool:

>>>> Window <<<<
Title:    MyPlan
Class:    mijnplan
Position:    0, 0
Size:    1288, 988
Style:    0x14CF0000
ExStyle:    0x00000100
Handle:    0x00000000000B09A2

>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    101
Text:    Add
Position:    138, 339
Size:    26, 28
ControlClick Coords:    17, 17
Style:    0x50010080
ExStyle:    0x00000000
Handle:    0x0000000000070A4E

Share this post


Link to post
Share on other sites
JLogan3o13

You're ControlClick is referencing [CLASS:mymdchildp], but the output you're showing is for [CLASS:Button]. Have you tried simply something like this?

ControlClick("MyPlan", "", "Button1")

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Eusch

Is there a parent/child relationchip between the windows from the view of autoit? Normally you need a parent to find a child window, The win32 funtion FindWindow() only works on top level windows, From there on you need to traverse the window tree to find the one youre interested in.

 

Share this post


Link to post
Share on other sites
Eusch
ControlClick("MyPlan", "", "Button1")

Does not work. Could it have something to do with the windows hierarchy: top level window MyPlan (class=mijnplan) - Mdiclient area (class=mdiclient) - mdichild (class=mdichild) - dialog window (class=#32770) - button (class=button)?

Share this post


Link to post
Share on other sites
JLogan3o13

So, the button is on the dialog window, correct?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Eusch

Yes, but it's a dialog created with CreateDialog() but has the mdi child window as parent. In the screenshot it

s the button at bottom left.

 

test.png

Edited by Eusch
More detail

Share this post


Link to post
Share on other sites
JLogan3o13

Please share a screenshot of the AutoIt Window Info Tool readout for that button, if it is different than what you have in post #3. If that is the same, let me know


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Eusch

I think it's the same, nevertheless the screenshots anyway

 

Image3.png

Image4.png

>>>> Window <<<<
Title:    MyPlan
Class:    mijnplan
Position:    -4, -4
Size:    1288, 988
Style:    0x15CF0000
ExStyle:    0x00000100
Handle:    0x00000000002509E4

>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    101
Text:    Add
Position:    181, 403
Size:    26, 28
ControlClick Coords:    15, 17
Style:    0x50010080
ExStyle:    0x00000000
Handle:    0x00000000000C0B4C

>>>> Mouse <<<<
Position:    196, 458
Cursor ID:    0
Color:    0xD4D0C8

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Instructors
&Name:
Add
Edit
Delete
Search


>>>> Hidden Text <<<<
Add
Cancel
Edit
Cancel
Deactivate
Activate
Cancel
Search
Cancel
 

Edited by Eusch

Share this post


Link to post
Share on other sites
Eusch

It has become very silent. My problem is still not resolved. 

Share this post


Link to post
Share on other sites
Earthshine

Dialog Class window is #32770, therefore it should be something like this.

ControlClick('[CLASS:#32770]', 'Instructors', '[CLASS:Button; INSTANCE:1]')

here is a function i wrote that waits forever for controls or until a timeout happens. if you don't use log4a.au3 then just make those calls ConsoleWrite

#include-once
#include <Timers.au3>
#include "log4a.au3"

; #FUNCTION# ====================================================================================================================
; Name ..........: _checkClickCtrl
; Description ...: Automatically wait for a control to exist. Forever or Limited
; Syntax ........: _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout, $delayafter
; Parameters ....: $formclass           - Form Class info.
;                  $text                - Windows text to match
;                  $ctrl                - Class of Copntrol
;                  $ctrltxt             - Text of the Control
;                  $timeout             - Timeout = 0 by default, millisecond timer
;                  $delayafter          - Time in milliseconds to delay after operation carried out
; Return values .: None
; Author ........: Peter Martin
; Modified ......:
; Remarks .......:  Waits for each button indefinatly, unless you give it a timeout
;                   Logger found here: https://www.autoitscript.com/forum/topic/156196-log4a-a-logging-udf/
; Related .......:
; Link ..........:
; Example(s) ....:  _checkClickCtrl ('[CLASS:#32770]', 'ApplicationX - InstallShield Wizard', '[CLASS:Button; INSTANCE:1]', , '&Next >' 5000, 0)
;                   _checkClickCtrl($formclass, $text, $button2, $TD_BTN_REMOVE, 0, 0)
;                   _checkClickCtrl($formclass, $text, $button3, $TD_BTN_NEXT, 0, 500)
;                   _checkClickCtrl($formclass, $text, $button1, $TD_BTN_YES, 0, 0)
;                   _checkClickCtrl($formclass, $text, $button4, $TD_BTN_FINISH, 0, 0)
; ===============================================================================================================================
Func _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout = 0, $delayafter = 0)
    _log4a_Info("_checkClickCtrl():Begin")
    _log4a_Info("Searching for Formclass: " & $formclass)
    _log4a_Info("Searching for Text: " & $text)
    _log4a_Info("Searching for Control: " & $ctrl)
    _log4a_Info("Searching for Ctrl Txt: " & $ctrltxt)
    _log4a_Info("Timeout: " & $timeout)
    _log4a_Info("Time Delay (after click): " & $delayafter)
    Local $time_run = _Timer_Init()
    While (1)
        If WinExists($formclass) Then
            Local $hCtrl = ControlGetHandle($text, '', $ctrl)
            If $hCtrl Then
                If ($timeout > 0) Then
                    _log4a_Info(_Timer_Diff($time_run))
                    If (_Timer_Diff($time_run) > $timeout) Then
                        _log4a_Info("ExitLoop:Timeout - " & $ctrl)
                        ExitLoop
                    EndIf
                EndIf
                Local $hCtrlHandle = ControlGetText($text, '', $ctrl)
                _log4a_Info("Control Text Search: " & $ctrltxt)
                _log4a_Info("Control Text Found: " & $hCtrlHandle)
                If ($hCtrlHandle == $ctrltxt) Then
                    ; we got the handle, so the button is there
                    ; now do whatever you need to do
                    _log4a_Info("Found Formclass: " & $formclass)
                    _log4a_Info("Found Text: " & $text)
                    _log4a_Info("Found Control: " & $ctrl)
                    _log4a_Info("Found Ctrl Txt: " & $ctrltxt)
                    _log4a_Info("Timeout: " & $timeout)
                    _log4a_Info("Time Delay (after click): " & $delayafter)
                    _log4a_Info($ctrl)
                    ControlClick($formclass, '', $ctrl)
                    If ($delayafter > 0) Then
                        Sleep($delayafter)
                    EndIf
                    _log4a_Info("ExitLoop:Normal - " & $ctrl)
                    ExitLoop
                EndIf
            EndIf
        EndIf
    WEnd
    _log4a_Info("_checkClickCtrl():End")
EndFunc   ;==>_checkClickCtrl

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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

×