Jump to content

Can I pass a control handle to ControlClick instead of a controlID?


Michiel
 Share

Recommended Posts

This works:

ControlClick($hWnd, "", "[TEXT:J'accepte/I Agree]")

But this does not:
 

Local $hBtn = ControlGetHandle($hWnd, '', "[TEXT:J'accepte/I Agree]")
ControlClick($hWnd, "", $hBtn)

(When checking if a handle is correctly returned by dumping it to the screen MsgBox, it is indeed.)

Is it possible in the first place to click a control using a handle to a control rather than an id? Just curious.

Link to comment
Share on other sites

This is because ControlClick works with The control to interact with, not the handle. So, you must use a control as such:

ID - The internal control ID. The Control ID is the internal numeric identifier that windows gives to each control. It is generally the best method of identifying controls. In addition to the AutoIt Window Info Tool, other applications such as screen readers for the blind and Microsoft tools/APIs may allow you to get this Control ID
    TEXT - The text on a control, for example "&Next" on a button
    CLASS - The internal control classname such as "Edit" or "Button"
    CLASSNN - The ClassnameNN value as used in previous versions of AutoIt, such as "Edit1"
    NAME - The internal .NET Framework WinForms name (if available)
    REGEXPCLASS - Control classname using a regular expression
    X \ Y \ W \ H - The position and size of a control.
    INSTANCE - The 1-based instance when all given properties match.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

The handle can be used, of course :geek:

Run ("notepad")
$hNotepad = WinWait("[CLASS:Notepad]")
$hEdit = ControlGetHandle($hNotepad, "", "[CLASS:Edit]")

WinActivate($hNotepad)
; ControlSend($hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "text")
ControlSend($hNotepad, "", $hEdit, "text")

Edit : $hEdit instead of "[CLASS:Edit; INSTANCE:1]" (i wrote to fast)

Edited by jguinch
Link to comment
Share on other sites

jguinch I think you are a little confused.

you haven't even used a handle to do anything in that example. :sweating:

EDIT: You were correct about it working though, as this works.

Run ("notepad")
$hNotepad = WinWait("[CLASS:Notepad]")
$hEdit = ControlGetHandle($hNotepad, "", "[CLASS:Edit]")

WinActivate($hNotepad)
ControlSend($hNotepad, "", $hEdit, "text")
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Your first post is about ControlClick

ControlClick($hWnd, "", "[TEXT:J'accepte/I Agree]")
Local $hBtn = ControlGetHandle($hWnd, '', "[TEXT:J'accepte/I Agree]")
ControlClick($hWnd, "", $hBtn)

 

So, anything else we were misinformed on? :geek:

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

I don't understand...

Look at your first post. It says:

 

This works:

ControlClick($hWnd, "", "[TEXT:J'accepte/I Agree]")

But this does not:

 

Local $hBtn = ControlGetHandle($hWnd, '', "[TEXT:J'accepte/I Agree]") ControlClick($hWnd, "", $hBtn)

(When checking if a handle is correctly returned by dumping it to the screen MsgBox, it is indeed.)

Is it possible in the first place to click a control using a handle to a control rather than an id? Just curious.

Then later you said you wanted to send text not a click.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

People we're using ControlSend as an example to show yes you can use hwnd of control I also got confused.

If it is not working for your particular control, then just use the one that does.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Ah ... a misunderstanding :sweating:

Yes, sorry about that.

Your code should work...

Local $hBtn = ControlGetHandle($hWnd, '', "[TEXT:J'accepte/I Agree]")
ControlClick($hWnd, "", $hBtn)

Provided that you have the correct $hWnd.

If it does not then you really should just use your first example that does.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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...