Jump to content

State of a check box


MPlb
 Share

Recommended Posts

Is it possible to detect whether a check box is ticked or unticked? I am trying write something that launches an application (Outlook for example) and then displays a certain pages of that application that contains various options and see what options are ticked.

Launching the app and getting to the relevant page is no problem. However, I can't work out how to reference the actual check box fields. Is this possible with AutoIt v3?

Thanks

Link to comment
Share on other sites

I am assume this is an AutoIt GUI.

The following does what you want in a basic manner. A quick flick through of the help file would have told you this.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 227, 78, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Open Google", 8, 8, 210, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 8, 32, 210, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 8, 56, 210, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case GUICtrlRead ($Checkbox1) = $GUI_CHECKED
            MsgBox (0, "", "checked!")
    EndSelect
WEnd

There is a problem though! We'll get the message again and again! We have two options, one is to immediately uncheck the check box. But we may not want that so there is another way (one of several).

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $check1_state = False, $check2_state = False, $check3_state = False
$Form1 = GUICreate("Form1", 227, 78, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Open Google", 8, 8, 210, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 8, 32, 210, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 8, 56, 210, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case (GUICtrlRead ($Checkbox1) = $GUI_CHECKED) AND ($check1_state = False)
            $check1_state = True
            MsgBox (0, "", "checked!")
        Case GUICtrlRead ($Checkbox1) = $GUI_UNCHECKED
            $check1_state = False
    EndSelect
WEnd

If you are feeling adventurous you may even try using a dummy control.

Cheers,

Brett

Edited by BrettF
Link to comment
Share on other sites

Link to comment
Share on other sites

Hi Yashied

That along with ControlCommand let me do exactly what I wanted. I also used the AU3Info utility to show me the information about the controls on the relevant windows.

Thanks for the help...

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