Zain Ali
Zain Ali

Reputation: 15983

Set control text in AutoIt with out window text and title

I am quite newbie to autoit. I have 2 questions.

  1. How to use ControlFocus ( "", "", "[X:643;Y:339]" ) when widow has no text and no title.Please look at following information of window and control viewed by window informer.

Window <<<< Title: Class: WindowsForms10.Window.8.app.0.33c0d9d Position: 0, 0 Size: 1024, 768 Style: 0x16010000 ExStyle: 0x00010000 Handle: 0x005201E0

Control <<<< Class: WindowsForms10.EDIT.app.0.33c0d9d Instance: 2 ClassnameNN: WindowsForms10.EDIT.app.0.33c0d9d2 Name: txtConsumerNo Advanced (Class): [NAME:txtConsumerNo] ID: 15270262 Text: Position: 638, 237 Size: 263, 30 ControlClick Coords: 38, 27 Style: 0x560100C0 ExStyle: 0x00000200 Handle: 0x00E90176

How is it possible to interact with this control?

  1. I want to call text change event of a this control. How is it possible

Upvotes: 0

Views: 8730

Answers (1)

Jos van Egmond
Jos van Egmond

Reputation: 2360

If you are dealing with a window without text and a title, it may be easier to first get the handle to the window with WinGetHandle. You can get the handle from the active window like so:

$hWnd = WinGetHandle("[ACTIVE]")

For interacting with the control you have a lot of options. Your best option is probably to use the Name of the control, which is: txtConsumerNo. If you then use ControlFocus like so it will work. Note that $hWnd comes from the above WinGetHandle statement.

ControlFocus($hWnd, "", "[NAME:txtConsumerNo]")

I recommend against using the X and Y position of the control. It can have a hard time finding the correct control. When other methods are available, such as the name or the class, those are very much preferred.

You can change the text of another control in AutoIt with the ControlSetText method. It will call the 'text change event' for you automatically. See the help file for the documentation about ControlSetText. It works in a similar way to ControlFocus.

Upvotes: 3

Related Questions