Jump to content

Using control handle to access controls...


pim slim
 Share

Recommended Posts

Hi,

AutoItX newbie here... I'm having some problems with control handles, and I was wondering if you guys could help me. I'm trying to use a control's handle in a call to ControlSetText (FYI: I'm using C#), but it doesn't seem to work. It works perfectly when I use classname or controlID, but for my application I'd like to be able to use the control handle.

I have the following code:

AutoItX3Class a = new AutoItX3Class();
a.Run(exename, dirname, 1);
a.WinWait(apptitle, "", 1000);
string hWnd = a.WinGetHandle(apptitle, "");
a.AutoItSetOption("WinTitleMatchMode", 4);

// a.ControlSetText("handle=" + hWnd, "", "Static1", "Test"); // classname works
// a.ControlSetText("handle=" + hWnd, "", "4", "Test"); // control ID works

// the following attempts using hCtl do not work :(
string hCtlHex = a.ControlGetHandle("handle=" + hWnd, "", "Static1");
string hCtlDecimal = Convert.ToInt32(hCtlHex, 16).ToString();

a.ControlSetText("handle=" + hWnd, "", hCtlHex, "Test");
a.ControlSetText("handle=" + hWnd, "", hCtlDecimal, "Test");
a.ControlSetText("handle=" + hWnd, "", "handle=" + hCtlHex, "Test");
a.ControlSetText("handle=" + hWnd, "", "handle=" + hCtlDecimal, "Test");
a.ControlSetText("handle=" + hWnd, "", "0x" + hCtlHex, "Test");

Does anyone have an idea what I'm doing wrong? The only thing I can think of is that maybe the control handle is supposed to be passed to ControlSetText as an int instead of a string, but that's impossible because ControlSetText expects a string argument.

I would be most thankful if there was anyone out there who could lead me out of the darkness.

Edited by pim slim
Link to comment
Share on other sites

Using the AutoIt Window Info Tool you can move your mouse around the window you are interested in and you will be given information of the control that is currently under your mouse. Information on controls is given in a number of ways, these are:

Control ID

ClassNameNN

Text

Whenever you see a Control...() command expecting a ControlID parameter (most of them) you can use any one of these methods. The method you choose will vary by personal preference and the information you are able to retrieve from the AutoIt Window Info Tool. In general, the best method to use is the Control ID, with the other methods being used when a Control ID is not available or is not unique (usually with static text each piece of text actually has the same Control ID so you will need to use one of the other methods to work with those controls).

The above is from the AutoitX v3 help file (AutoItX.chm), on page "Controls". As you can see there (and in the excerpt above), Control Handle is not among the methods to identify the control.

There are differences between AutoItX.chm helpfile and the AutoIt.chm helpfile. in AutoIt a control handle is allowed, but not in AutoItX. And in AutoIt handle seems to be its own data type, in AutoItX we say, for windows, "handle="+ (hex string)HWND. Also access to the Page "Controls" in the AutoItX help is indirect: I've seen a link on most Controlxxxx pages, e.g. ControlGetText, ControlGetHandle, look for it in the controlID parameter explanation. In a similar sense WinList is in AutoIt, but not (yet) in AutoItX.

Problems might arise when a control is first identified by its text contents, and then text is changed. There isn't a ControlGetID function either - I'm not sure if WinGetClassList allows a work-around, and did not try.

PS I deleted an earlier reply and edited this one. PPS I'm a newbie too. AutoItX is very functional and helpful.

Edited by PeterSwiss
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...