Jump to content
Sign in to follow this  
MPlb

State of a check box

Recommended Posts

MPlb

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

Share this post


Link to post
Share on other sites
BrettF

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

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
MPlb

Thanks for the replies but I'm not talking about an AutoIT Gui. I'm wanting to check the state of check boxes on an application such as Outlook or Excel which I am launching with AutoIT.

Share this post


Link to post
Share on other sites
Yashied
MPlb

I'm just going to try it now...

Share this post


Link to post
Share on other sites
MPlb

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

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  

×