sagirajuramaraju Posted May 25, 2009 Posted May 25, 2009 Hi, I have a checkbox in my application. I want to check whether the checkbox is checked or not. I tried with GUICtrlRead(), but I didn't get any output. My checkbox has the following Inforamtion ClassName Caption TypeName ID style Using the above properties how can I resolve my question Thanks in Advance.
martin Posted May 25, 2009 Posted May 25, 2009 (edited) Hi,I have a checkbox in my application. I want to check whether the checkbox is checked or not.I tried with GUICtrlRead(), but I didn't get any output. My checkbox has the following InforamtionClassNameCaptionTypeNameIDstyleUsing the above properties how can I resolve my questionThanks in Advance.You find the state of the checkbox. If the state include $GUI_CKECKED then it is checked.$IsChecked = GuiCtrlRead($ChkBox1) = $GUI_CHECKEDWelcome to the AutoIt forums sagirajuramaraju EDIT: Corrected wrong advice Edited May 25, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
sagirajuramaraju Posted May 25, 2009 Author Posted May 25, 2009 You find the state of the checkbox. If the state include $GUI_CKECKED then it is checked.$IsChecked = BitAnd(GuiCtrlGetState($ChkBox1),$GUI_CHECKED)Welcome to the AutoIt forums sagirajuramaraju Can you give descriptive example because still I didn't get that result. Can you know how can I know the checkbox ObjectType
Authenticity Posted May 25, 2009 Posted May 25, 2009 #include <GuiConstants.au3> Global $hGUI Global $CheckBox $hGUI = GUICreate('Test', 100, 50) $CheckBox = GUICtrlCreateCheckbox('Unchecked', 10, 15, 80, 23) GUISetState() While 1 Switch GUIGetMsg() Case $CheckBox If GUICtrlRead($CheckBox) = $GUI_CHECKED Then GUICtrlSetData($CheckBox, 'Checked') Else GUICtrlSetData($CheckBox, 'Unchecked') EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() Exit
martin Posted May 25, 2009 Posted May 25, 2009 Can you give descriptive example because still I didn't get that result. Can you know how can I know the checkbox ObjectType Apologies, GuiCtrlGetState doesn't return with the checked state information, as the help says Function GUICtrlGetStateFunction GUICtrlGetStateAs opposed to GUICtrlRead this function returns ONLY the state of a control enabled/disabled/hidden/show/dropacceptedwhereas GuiCtrlRead only return the checked state of a check box, as in Authenticity's example. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Zedna Posted May 25, 2009 Posted May 25, 2009 (edited) Here is correct way: #include <GuiConstants.au3> Global $hGUI Global $CheckBox $hGUI = GUICreate('Test', 100, 50) $CheckBox = GUICtrlCreateCheckbox('Unchecked', 10, 15, 80, 23) GUISetState() While 1 Switch GUIGetMsg() Case $CheckBox If IsChecked($CheckBox) Then GUICtrlSetData($CheckBox, 'Checked') Else GUICtrlSetData($CheckBox, 'Unchecked') EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() Exit Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc This works fine also in case checkbox has other styles than checked/unchecked at the same time - for example disabled,... Edited May 25, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
martin Posted May 25, 2009 Posted May 25, 2009 Here is correct way: #include <GuiConstants.au3> Global $hGUI Global $CheckBox $hGUI = GUICreate('Test', 100, 50) $CheckBox = GUICtrlCreateCheckbox('Unchecked', 10, 15, 80, 23) GUISetState() While 1 Switch GUIGetMsg() Case $CheckBox If IsChecked($CheckBox) Then GUICtrlSetData($CheckBox, 'Checked') Else GUICtrlSetData($CheckBox, 'Unchecked') EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() Exit Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc This works fine also in case checkbox has other styles than checked/unchecked at the same time - for example disabled,... No, I think you are wrong Zedna. I used to think that but I tried GuiCtrlRead with disabled and enabled check boxes and it still gives the correct result. expandcollapse popup#include <GuiConstantsEx.au3> Global $hGUI Global $CheckBox, $CheckEnable, $Btn $hGUI = GUICreate('Test', 170, 250) $CheckBox = GUICtrlCreateCheckbox('Unchecked', 10, 15, 80, 23) $Btn = GUICtrlCreateButton("read checkbox state", 5, 90, 130, 22) $CheckEnable = GUICtrlCreateCheckbox("disabled checkbox state ", 10, 150, 120, 22) GUISetState() $chkEnabled = True While 1 Switch GUIGetMsg() Case $CheckBox If GUICtrlRead($CheckBox) = $GUI_CHECKED Then GUICtrlSetData($CheckBox, 'Checked') Else GUICtrlSetData($CheckBox, 'Unchecked') EndIf Case $Btn $IsChecked = GuiCtrlRead($CheckBox) = $GUI_CHECKED ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF) If GuiCtrlRead($CheckBox) = $GUI_UNCHECKED Then MsgBox(262144, "check box is", 'UnChecked') Else MsgBox(262144, "check box is", 'checked') EndIf Case $CheckEnable ConsoleWrite("check en" & @CRLF) $ChkEnabled = Not $ChkEnabled If $ChkEnabled Then GUICtrlSetState($CheckBox, $GUI_ENABLE) GUICtrlSetData($CheckEnable, "disabled checkbox state ") Else GUICtrlSetData($CheckEnable, "enabled checkbox state ") GUICtrlSetState($CheckBox, $GUI_DISABLE) EndIf Case $GUI_EVENT_CLOSE Exit;Loop EndSwitch WEnd Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
sagirajuramaraju Posted May 26, 2009 Author Posted May 26, 2009 I agree with you people, but here all the examples for new checkbox (that we need to create first then checking the property). That is not my question I have already a checkbox, I don't want to use GUICtrlCreateCheckbox, just I want to know the property of the existing checkbox No, I think you are wrong Zedna. I used to think that but I tried GuiCtrlRead with disabled and enabled check boxes and it still gives the correct result. expandcollapse popup#include <GuiConstantsEx.au3> Global $hGUI Global $CheckBox, $CheckEnable, $Btn $hGUI = GUICreate('Test', 170, 250) $CheckBox = GUICtrlCreateCheckbox('Unchecked', 10, 15, 80, 23) $Btn = GUICtrlCreateButton("read checkbox state", 5, 90, 130, 22) $CheckEnable = GUICtrlCreateCheckbox("disabled checkbox state ", 10, 150, 120, 22) GUISetState() $chkEnabled = True While 1 Switch GUIGetMsg() Case $CheckBox If GUICtrlRead($CheckBox) = $GUI_CHECKED Then GUICtrlSetData($CheckBox, 'Checked') Else GUICtrlSetData($CheckBox, 'Unchecked') EndIf Case $Btn $IsChecked = GuiCtrlRead($CheckBox) = $GUI_CHECKED ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF) If GuiCtrlRead($CheckBox) = $GUI_UNCHECKED Then MsgBox(262144, "check box is", 'UnChecked') Else MsgBox(262144, "check box is", 'checked') EndIf Case $CheckEnable ConsoleWrite("check en" & @CRLF) $ChkEnabled = Not $ChkEnabled If $ChkEnabled Then GUICtrlSetState($CheckBox, $GUI_ENABLE) GUICtrlSetData($CheckEnable, "disabled checkbox state ") Else GUICtrlSetData($CheckEnable, "enabled checkbox state ") GUICtrlSetState($CheckBox, $GUI_DISABLE) EndIf Case $GUI_EVENT_CLOSE Exit;Loop EndSwitch WEnd
Authenticity Posted May 26, 2009 Posted May 26, 2009 lol sorry, I think we all misunderstood the subject. Lookup ControlCommand() in the help file, "IsChecked", "".
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now