Jump to content

Checking the state of a check box


Surgery
 Share

Recommended Posts

Hi,

I did some searching on this and I get the impression that it involves using the BitAND function, but I don't really understand how it works precisely, nor how I would use it on a form I didn't create in AutoIt. What I'm trying to do is automate a configuration process, and part of that involves going through a list of check boxes, and turning one of them on. If that checkbox is already checked I don't want to check it again, thus unchecking it. Thanks.

Link to comment
Share on other sites

And an example:

GUICreate('Example',200,200)
$CHECKBOX = GUICtrlCreateCheckbox("This is a test",25,25,100,20)
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then
        Exit
    EndIf
    If GUICtrlRead($CHECKBOX) = 1 Then 
        $STATE = "CHECK"
    Else
        $STATE = "UNCHECK"
    EndIf
    TrayTip("Checkbox State",$STATE,1)
    Sleep(20)
WEnd
Link to comment
Share on other sites

And an example:

GUICreate('Example',200,200)
$CHECKBOX = GUICtrlCreateCheckbox("This is a test",25,25,100,20)
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then
        Exit
    EndIf
    If GUICtrlRead($CHECKBOX) = 1 Then 
        $STATE = "CHECK"
    Else
        $STATE = "UNCHECK"
    EndIf
    TrayTip("Checkbox State",$STATE,1)
    Sleep(20)
WEnd
GuiCtrlRead($CHECKBOX) = $GUI_CHECKED and $GUI_UNCHECKED will do the samething aswell.
Link to comment
Share on other sites

Hi,

I did some searching on this and I get the impression that it involves using the BitAND function, but I don't really understand how it works precisely, nor how I would use it on a form I didn't create in AutoIt. What I'm trying to do is automate a configuration process, and part of that involves going through a list of check boxes, and turning one of them on. If that checkbox is already checked I don't want to check it again, thus unchecking it. Thanks.

Try this:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("_IsChecked Example", 250, 100)
$CheckBox = GUICtrlCreateCheckbox("CheckBox", 25, 25)
GUICtrlSetState(-1, $GUI_CHECKED)

GUISetState()

;This shows that it can be used on external GUIs
MsgBox(64, "_IsChecked", "$CheckBox _IsChecked: " & (_IsChecked("_IsChecked Example", "Button1") = 1), 0, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CheckBox
            ConsoleWrite("$CheckBox _IsChecked: " & _IsChecked($hGUI, $CheckBox) & @CRLF)
    EndSwitch
WEnd

Func _IsChecked($sTitle, $iCtrlID)
    Return ControlCommand($sTitle, "", $iCtrlID, "IsChecked")
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@Zedna and others:

As i understood, the OP needs to check not only AutoIt GUI...

how I would use it on a form I didn't create in AutoIt

So the “IsChecked” command in ControlCommand() is the best solution for both needs :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

That ControlCommand with the "isChecked" seems like it would work, but I'm having trouble figuring out how to identify the checkbox. I'm trying to set one of the checkboxes in this window to checked. But when I use the window inspector it just gives me one ID and one title for that entire menu of checkboxes. I've also tried using Send({-} {+}); to uncheck it, then check it, but that doesn't seem to be very reliable. I appreciate all the responses though, and once I figure out the above problem they'll probably be very useful. Thanks.

post-28225-1229987409_thumb.jpg

Link to comment
Share on other sites

That ControlCommand with the "isChecked" seems like it would work, but I'm having trouble figuring out how to identify the checkbox. I'm trying to set one of the checkboxes in this window to checked. But when I use the window inspector it just gives me one ID and one title for that entire menu of checkboxes. I've also tried using Send({-} {+}); to uncheck it, then check it, but that doesn't seem to be very reliable. I appreciate all the responses though, and once I figure out the above problem they'll probably be very useful. Thanks.

ControlTreeView should work here, but it's always return -1 for me:

Opt("WinDetectHiddenText", 1)

WinActivate("[CLASS:#32770]", "Privacy Slider")
$IsCheccked = ControlTreeView("[CLASS:#32770]", "Privacy Slider", "SysTreeView321", "IsChecked", "#1|#0")

ConsoleWrite($IsCheccked & @CRLF)oÝ÷ Ø­¶zWµÊ&©ÝÌ(®H§«­¢+Ù=ÁÐ ÅÕ½Ðí]¥¹ÑÑ!¥¹QáÐÅÕ½Ðì°Ä¤()]¥¹Ñ¥ÙÑ ÅÕ½Ðím
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐíAÉ¥ÙäM±¥ÈÅÕ½Ðì¤()
½¹Ñɽ±QÉY¥Ü ÅÕ½Ðím
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐíAÉ¥ÙäM±¥ÈÅÕ½Ðì°ÅÕ½ÐíMåÍQÉY¥ÜÌÈÄÅÕ½Ðì°ÅÕ½ÐíM±ÐÅÕ½Ðì°ÅÕ½ÐìÅðÄÅÕ½Ðì¤(ÀÌØíÍM±Ñô
½¹Ñɽ±QÉY¥Ü ÅÕ½Ðím
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐíAÉ¥ÙäM±¥ÈÅÕ½Ðì°ÅÕ½ÐíMåÍQÉY¥ÜÌÈÄÅÕ½Ðì°ÅÕ½ÐíÑM±ÑÅÕ½Ðì¤(ÀÌØí%Í
¡­ô
½¹Ñɽ±QÉY¥Ü ÅÕ½Ðím
1MLèÌÈÜÜÁtÅÕ½Ðì°ÅÕ½ÐíAÉ¥ÙäM±¥ÈÅÕ½Ðì°ÅÕ½ÐíMåÍQÉY¥ÜÌÈÄÅÕ½Ðì°ÅÕ½Ðí%Í
¡­ÅÕ½Ðì°ÀÌØíÍM±Ñ¤()
½¹Í½±]É¥Ñ ÀÌØí%Í
¡­µÀì
I1

:)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

The ClassNameNN of the control is SysTreeView321.

I'll check out ControlTreeView and see what results I get. I hope I don't have to mess with the registry, I may end up way over my head. I agree, it is a head scratcher.

update: I get the same results as MrCreatoR with "Settings" in place of "Privacy Slider". Select seems to be working correctly, but I get -1 when I do IsChecked.

Edited by Surgery
Link to comment
Share on other sites

It's working with _GUICtrlTreeView_GetImageIndex()...

#include <GuiTreeView.au3>

;Opt("WinDetectHiddenText", 1)

If Not WinActivate("[CLASS:#32770]", "&") Then
    MsgBox(48, "Error", "Window not found." & @CRLF & @CRLF & "OK ==> EXIT", 3)
    Exit
EndIf

$h_TreeView = ControlGetHandle("[CLASS:#32770]", "&", "SysTreeView321")

$s_TextByIndex_1 = ControlTreeView("[CLASS:#32770]", "&", "SysTreeView321", "GetText", "#1|#0")
$s_TextByIndex_2 = ControlTreeView("[CLASS:#32770]", "&", "SysTreeView321", "GetText", "#1|#2")

$h_Item_1 = _GUICtrlTreeView_FindItem($h_TreeView, $s_TextByIndex_1)
$h_Item_2 = _GUICtrlTreeView_FindItem($h_TreeView, $s_TextByIndex_2)

$IsChecked_1 = "ERROR"
$IsChecked_2 = "ERROR"

If $h_Item_1 <> 0 Then $IsChecked_1 = _GUICtrlTreeView_GetImageIndex($h_TreeView, $h_Item_1) = 0
If $h_Item_2 <> 0 Then $IsChecked_2 = _GUICtrlTreeView_GetImageIndex($h_TreeView, $h_Item_2) = 0

$sResults = StringFormat( _
    'First Index in "Security" (%s) IsChecked = %s\n' & _
    'Third Index in "Security" (%s) IsChecked = %s\n', $s_TextByIndex_1, $IsChecked_1, $s_TextByIndex_2, $IsChecked_2)

ConsoleWrite($sResults)

:)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

GetImageIndex seems to be working great now. Thanks for the help guys. Now, I'm trying to use SetImageIndex to check the box if it is unchecked, but it doesn't seem to do anything:

_GUICtrlTreeView_SetImageIndex($h_TreeView, $h_Item_1, 0)

I've also tried sending a tab, several down keystrokes, and a {+} and that doesn't work, and also tried "Check" and "Uncheck" using ControlTreeView and neither of those works either. I get the feeling I'm misunderstanding SetImageIndex in some way. And again, thanks so much for all the help guys, very much appreciated.

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