Sign in to follow this  
Followers 0
Sh4rk

Checkbox status in Treeview and Listbox

12 posts in this topic

Im new to Autoit and i have just registered. :graduated:

My problem is to get the status of a checkbox, which is

1.) in a SysTreeView32 and

2.) in a Listbox

With help of the window info tool i only get the information above, no ID or class of the Checkboxes.

So how do I get the status of the checkboxes?

1.)

Posted Image

2.)

Posted Image

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The more advanced functions of the User Defined Functions (UDFs) will be required. You can find these in the help file, i.e. _GUICtrlTreeView_GetChecked() or _GUICtrlListView_GetItemChecked().

If you are familiar with Hwnd handles and the like it won't hurt, but you'll want to learn some basics first if you are completely new to this.

:graduated:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

ok. I looked up the functions in the help file.

But i don't understand what parameters are required in my case.

What parameter should I specify for the item? A name as string or an index?

I tried something like this, but it always returns false.

MsgBox(0, "Checkbox status", _GUICtrlTreeView_GetChecked("[CLASS:SysTreeView32; INSTANCE:1]", 1))

Share this post


Link to post
Share on other sites

You have to get the handle to the control, and the handle to the item. The UDF doesn't use AutoIt's specification strings or numeric indexes. It would look more like this:

#include <GuiTreeView.au3>

; ...

$hTreeView = ControlGetHandle("Extensions", "", "[CLASS:SysTreeView32; INSTANCE:1]")
$hItem = _GUICtrlTreeView_FindItem($hTreeView, "Median")
$bolChecked = _GUICtrlTreeView_GetChecked($hTreeView, $hItem)

MsgBox(64, "Result", "Checked = " & $bolChecked)

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

thanks for your code snippet, but unfortunately it does not work.

The function always returns false independent of the status :graduated:

Do you have antoher idea?

Share this post


Link to post
Share on other sites

Add some error checking. Which part of it failed? Did it get the correct handle for the control in $hTreeView (compare with value from AU3Info.exe)? Did it get a valid handle for the item in $hItem, or a zero (not found)?

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Here is screenshot of the Window Info:

Posted Image

For the treeView I get 0x000505E4, same as in window info.

For the item I get 0x079C3CE8, can't find that value in the window info.

So the handle seems to be correct..

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

That's good. You can only match the parent control handle via AU3Info.exe, it won't show you item handles under the control.

The item handle would be better tested with IsHwnd(), but that looks like it is probably a valid handle by the format.

With a valid handle for the control and the item, _GUICtrlTreeView_GetChecked() should have worked.

If you run the unmodified example script in the help file for _GUICtrlTreeView_GetChecked() on the same PC, does it work correctly?

Also, what is the OS?

:graduated:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The example script works correct. The OS is Windows XP (Service Pack 3).

I also tried $hItem = _GUICtrlTreeView_GetFirstItem($hTreeView) to get the first item, but without success.

It always returns false... :graduated:

Share this post


Link to post
Share on other sites

Hmmm... :graduated:

Try _GUICtrlTreeView_GetImageIndex() on the same item and see if you get a different result index for checked/unchecked.

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I tried the following:

$hTreeView = ControlGetHandle("Extensions", "", "[CLASS:SysTreeView32; INSTANCE:1]")
;$hItem = _GUICtrlTreeView_FindItem($hTreeView, "Median")
$hItem = _GUICtrlTreeView_GetFirstItem($hTreeView)
$index = _GUICtrlTreeView_GetImageIndex($hTreeView, $hItem)
MsgBox(64, "Result", "index = " & $index)

$bolChecked = _GUICtrlTreeView_GetChecked($hTreeView, $hItem)
MsgBox(64, "Result", "Checked = " & $bolChecked)

the first item has an image index of 3.

Shouldn't it be 0 or 1?

Share this post


Link to post
Share on other sites

the first item has an image index of 3.

And is it different when checked?

The image index is not a Boolean value, it is an integer index that specifies which image to show. If there are a dozen different images in the Image List, then there are that many different indexes. You might have images for Enabled/Unchecked, Enabled/Checked, Enabled/Gray-Checked, Disabled/Unchecked, Disabled/Checked, etc.

The point is that not all apps respond to every control message as expected. If you can't get that particular one to reply with the checked value as a Boolean, then check the image index to see if it changes usefully when checked/unchecked.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
Sign in to follow this  
Followers 0