Jump to content

Interacting with checkboxes on another application


raoul
 Share

Recommended Posts

I have been working with AutoItX for a while now. I needed to write a program in VB.NET that would interact with multiple other windows programs. So far, I have had no trouble working with the various controls - getting / setting text from textboxes, clicking buttons, moving sliders, etc. I thought I was about finished and the last things I have to do is be able to interact with checkboxes (and radiobuttons). I thought it would be fairly straightforward, but I haven't been able to figure it out, and searching around this forum hasn't solved it for me yet. I would appreciate any help that I can get. I figure this must be a standard thing to want to do, so I must be missing something.

What I thought I needed to do was a command like

Dim state As Integer

state = AutoIt.ControlTreeView(MainName, "", 1073, "IsChecked", "", "")

and then just evaluate state to see if it is a -1,0,1. This doesn't seem to do anything though. MainName is the title of the form and the checkbox handle is 1073. I am not sure about putting the extra1 and extra2 as "", "" - but it gives me a syntax error if I don't put something for the optional extras.

I must be missing something. I thought I should be able to toggle the state by using the following to click on it (just like a button), but it doesn't do anything either.

AutoIt.ControlClick(MainNameThermoTrak, "", 1073)

So, the last things I need to work out is how to check the state of checkboxes and radiobuttons in a different windows application, and how to check / uncheck them.

On a side question: From what I can tell, the AutoItX.dll doesn't have the fully library of controls in it. Is there a way to add them and gain the full functionality of the AutoIt library when using the DLL inside a vb.net program?

Link to comment
Share on other sites

Any thoughts on this? I have been working very hard on this, but not able to come up with a solution yet.

I have been using some basic window API calls, that I assume AutoIt is doing in the background. For some reason, the ID of the checkbox seems to change. However, I have been able to call functions from the User32.lib like FindWindow and FindWindowEx and get the proper handle of the control. Then I am able to use Sendmessage(hWnd,BM_click,0,0) to click on the checkboxes and radiobuttons just fine. However, when I try to use sendmessage(hWnd,BM_GetCheck,0,0) to see if they are checked or not, it fails and always returns 0.

Searching around the net, this appears to be a common thing since they moved on to the latest versions of .NET. Now you are recommended to use Iaccessible to interact with these controls. However, I have not been successful in working out how to do it, so I am still hoping there is a way to do it in AutoIt and someone will show me how.

-R

Link to comment
Share on other sites

Look at ControlCommand() + IsChecked/Check/UnCheck in Autoit.

But I have no experience with AutoitX.

Thanks Zedna for the response. I don't think the AutoitX part matters. I was thinking about moving the question out to the general help and questions forum, as if someone can show me an example of it working, then I will worry about the autoitX part.

Anyway, I tried your suggestion, and it still does the same thing. For whatever reason, the checked state of checkboxes and radiobuttons doesn't seem to be easily accessible anymore. I think it will work on older applications, but anything written in the last few years in .NET doesn't seem to work. As a test, i made a simple application which has nothing but a checkbox on it. I can see if the checkbox is visible or not, so I seem to be interacting with it ok. However, i cannot query if it is checked or not. If someone can give me a line of script that does this (even if not autoitX) I would very much appreciate it!!!

My sub that does NOT work trying ControlCommand

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim state As Integer = Nothing

Dim formname As String = "TestFormName"

AutoIt.WinActivate(formname)

state = AutoIt.ControlCommand(formname, "", 1115520, "IsChecked", "")

MessageBox.Show(CStr(state))

End Sub

Link to comment
Share on other sites

Autoit can interact only with standard Windows controls.

In your case you are probably dealing with non-standard ones.

It is as standard as it can be. I made the test application myself and all I did was drag a standard checkbox on to the form. No frills...

Link to comment
Share on other sites

Instead of hard coding the controlID number, you should probably be trying to access it with one of the alternate controlID methods as shown in the help file. Look under ControlCommand for ways of accessing the checkbox controlID.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks guys for trying to help me through this. It

Instead of hard coding the controlID number, you should probably be trying to access it with one of the alternate controlID methods as shown in the help file. Look under ControlCommand for ways of accessing the checkbox controlID.

I hardcoded it just for this example. I have tried to access it using ClassnameNN and even the hWnd, but it behaves the same. i am 100% certain that I am accessing it correctly using the controlID, because I can use the same ControlCommand using "IsVisible" and it works perfectly. That is, i made a button on the test application that makes it visible or not, and the ControlCommand gets it right every time.

What ClassNameNN show Au3Info?

Au3Info shows:

WindowsForms10.BUTTON.app.0.2bf8098_r20_ad14

Link to comment
Share on other sites

Au3Info shows:

WindowsForms10.BUTTON.app.0.2bf8098_r20_ad14

This is non-standard control. It can't be controled by standard Win32 API.

There are topics on this forum about WindowsForms (.NET) controls but I have no experience with it.

As far as I can remember Jon wanted to add some support to Autoit for it but it wasn't solved/finished?

Try to search ...

Link to comment
Share on other sites

This is non-standard control. It can't be controled by standard Win32 API.

There are topics on this forum about WindowsForms (.NET) controls but I have no experience with it.

As far as I can remember Jon wanted to add some support to Autoit for it but it wasn't solved/finished?

Try to search ...

Yes, it is definitely a .NET control. I made it myself as a test bed for checkbox controls using VS.2010 .NET.

So, AutoIt doesn't work completely with .NET controls. That is unfortunate as more-and-more applications are written in .NET, so this will become a major issue. I have searched the forums and found posts where people are running into the same problem, but I haven't found a solution yet. *sigh* I am not sure where to go next on this problem. I have even contemplated examining the pixels at the checkbox location to see if it is checked or not, but it doesn't seem very robust. There has to be a solution, but it might not be through AutoIt unfortunately.

Link to comment
Share on other sites

  • 3 months later...

I have the same problem as well and still searching for a solution. What I have experienced so far with ControlCommand() is following:

ControlCommand("Title","text", "IsChecked","") --> this always return 0 no matter the botton is check or not

ControlCommand("Title","text", "UnCheck","") --> this is also not working for my case

But...

ControlCommand("Title","text", "Check","") --> this look like is working, I can get unchecked box to get a check thus not sure if you have try this for your case.

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