Jump to content
Sign in to follow this  

Radios and Checkboxes in the same window

Recommended Posts



I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.

I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.

I'd like to use one window with both checkboxes and radio buttons.

I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)

Func CheckOptions()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("SGX4CP Options", 275, 250)

    ; Create a checkbox control.
    Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25)
    Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25)
    Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25)
    GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED)

    Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25)
    Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25)
    GUICtrlSetState($iLogCheckbox, $GUI_CHECKED)
    Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose

            Case $iLoopCheckbox
                If _IsChecked($iLoopCheckbox) Then
                    $bLoopChecked = True
                    $bLoopChecked = False

            Case $iFullScreenCheckbox
                if _IsChecked($iFullScreenCheckbox) Then
                    $bFullScreenChecked = True
                    $bFullScreenChecked = False

            Case $iRestartPlaybackCheckbox
                if _IsChecked($iRestartPlaybackCheckbox) Then
                    $bRestartPlaybackChecked = True
                    $bRestartPlaybackChecked = False

            Case $iDisableSleepCheckbox
                if _IsChecked($iDisableSleepCheckbox) Then
                    $bDisableSleepChecked = True
                    $bDisableSleepChecked = False

            Case $iLogCheckbox
                if _IsChecked($iLogCheckbox) Then
                    $bLogChecked = True
                    $bLogChecked = False

    ; Delete the previous GUI and all controls.

Func RadioCheck()
    GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered

    Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10)
    Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40)
    Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70)
    GUICtrlSetState($idRadio1, $GUI_CHECKED)
    Local $idClose = GUICtrlCreateButton("Start Test", 120,100)


    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()
            Case $idMsg = $GUI_EVENT_CLOSE
            Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.')
                $bTestSelectForever = True
            Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.')
                $bTestSelect3Times = True
            Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.')
                $bTestSelectSingleVideo = True

I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.

I planned to remove the Loop checkbox and only enable it if Radio2 is selected.

Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?



Share this post

Link to post
Share on other sites

I'm sorry but it's really difficult to try and understand what you're trying to explain in your post (it's probably not you, pretty sure it's me). I think you mean you want a checkbox or a radio to only be available if another radio/checkbox is selected? Something like this?

#include <GUIConstants.au3>

Global $hMain = GUICreate("", 400, 400)
Global $rdo1 = GUICtrlCreateRadio("Radio 1", 10, 10, 100, 20)
Global $rdo2 = GUICtrlCreateRadio("Radio 2", 10, 35, 100, 20)
Global $aCheckBox1[4]
Global $aCheckBox2[10]

For $i = 0 to UBound($aCheckBox1) - 1
    $aCheckBox1[$i] = GUICtrlCreateCheckbox("[" & $i & "] Checkbox for Radio 1", 120, 10 + ($i * 20), 150, 20)
    GUICtrlSetState(-1, $GUI_HIDE)

For $i = 0 to UBound($aCheckBox2) - 1
    $aCheckBox2[$i] = GUICtrlCreateCheckbox("[" & $i & "] Checkbox for Radio 2", 120, 10 + ($i * 20), 150, 20)
    GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW, $hMain)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
        Case $rdo1
            ToggleCheckBoxes($aCheckBox2, $GUI_HIDE)
            ToggleCheckBoxes($aCheckBox1, $GUI_SHOW)
        Case $rdo2
            ToggleCheckBoxes($aCheckBox1, $GUI_HIDE)
            ToggleCheckBoxes($aCheckBox2, $GUI_SHOW)

Func ToggleCheckBoxes($aCheckBoxes, $iState)
    For $i = 0 to UBound($aCheckBoxes) - 1
        GUICtrlSetState($aCheckBoxes[$i], $iState)


Share this post

Link to post
Share on other sites

No, I want both Checkboxes and Radio buttons in the same window. I think I have a solution though.

Thanks for trying!

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  

  • Similar Content

    • rudi
      By rudi
      for some script I need to investigate the states checked/unchecked, hidden/shown, enabled/disabled to several checkbox controls.
      Any suggestions to this script to retrieve the information in a better way?
      ; Autoit Version ; GuiCtrlCheckState.au3 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $CtrlW = 100 $CtrlH = 30 $GuiW = 250 $GuiH = 300 GUICreate("Test Checkbox Status", $GuiW, $GuiH) $Ctrl = GUICtrlCreateCheckbox("Checkbox", 10, 10, $CtrlW, $CtrlH) Opt("Guicoordmode", 2) $BtnDisable = GUICtrlCreateButton("Disable", -1, 10) $BtnEnable = GUICtrlCreateButton("Enable", -1, 1) $BtnHide = GUICtrlCreateButton("Hide", 10, -$CtrlH * 2 - 1) $BtnUnHide = GUICtrlCreateButton("Show (Unhide)", -1, 1) $BtnCheckChecked = GUICtrlCreateButton("IsChecked", -$CtrlW * 2 - 10, 40) $BtnCheckEnabled = GUICtrlCreateButton("IsEnabled", -1, 1) $BtnCheckHidden = GUICtrlCreateButton("IsHidden", -1, 1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $BtnDisable GUICtrlSetState($Ctrl, $gui_disable) Case $BtnEnable GUICtrlSetState($Ctrl, $GUI_Enable) Case $BtnHide GUICtrlSetState($Ctrl, $GUI_Hide) Case $BtnUnHide GUICtrlSetState($Ctrl, $GUI_show) Case $BtnCheckChecked If CheckState($Ctrl, $GUI_CHECKED) Then ConsoleWrite("Checked" & @CRLF) Else ConsoleWrite("not checked" & @CRLF) EndIf Case $BtnCheckEnabled If CheckState($Ctrl, $GUI_Enable) Then ConsoleWrite("enabled" & @CRLF) Else ConsoleWrite("disabled" & @CRLF) EndIf Case $BtnCheckHidden If CheckState($Ctrl, $GUI_Hide) Then ConsoleWrite("Hidden" & @CRLF) Else ConsoleWrite("not hidden" & @CRLF) EndIf EndSwitch WEnd Func CheckState($_CtrlID, $_State = $GUI_CHECKED) ConsoleWrite("---------------------" & @CRLF) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_State to check = ' & $_State & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_Read = GUICtrlRead($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Read (GuiCtrlRead) = ' & $_Read & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_StateFound = GUICtrlGetState($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_StateFound (GuiCtrlGetState) = ' & $_StateFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console If $_StateFound = -1 Then MsgBox(48, "Control-ID not defined", "Control-ID invalid") Return False ElseIf BitAND($_StateFound, $_State) = $_State Then Return True ElseIf BitAND($_Read, $_State) = $_State Then Return True Else Return False EndIf EndFunc ;==>CheckState Regards, Rudi.
    • ur
      By ur
      I am trying to identify the window based on the window title and text.
      The title will be the "erwin DM - filename"

      It is working till date, but some operating systems our application is displaying window as "erwin DM - [filename]"
      I tried  "erwin DM - *filename*" But this regular expression is not working.
      Any suggestion?
      $sModelFile = "C:\Users\Administrator\Documents\My Models\eMovies.erwin" $wdModel = _WinWaitActivate1("erwin DM - "&FileNameOnly($sModelFile),"") Func _WinWaitActivate1($title,$text,$timeout=0);Will Return the window Handler Logging("Waiting for "&$title&":"&$text) $dHandle = WinWait($title,$text,$timeout) if not ($dHandle = 0) then If Not WinActive($title,$text) Then WinActivate($title,$text) return WinWaitActive($title,$text,$timeout) Else Logging("Timeout occured while waiting for the window...") Exit EndIf EndFunc Func FileNameOnly($sFilePath) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) ;_ArrayDisplay($aPathSplit, "_PathSplit of " & @ScriptFullPath) return $sFileName EndFunc  
    • gillesg
      By gillesg
      I am struggling in merging GUITreeViewEx, Shelltristate and enhancing to handle a third state that means : some items under are selected.
      I have difficulties handling expand order and key Space (especially when node is collapsed).
      Here the zip with UDF and and example.
      The problem I might need some advice to handle : 
      1- When load Treeview, have a correct settings of the checkbox for a tristate tree
      2 - Handle keyboard used for walking in tree
           Chicken is checked and  Steak is unchecked
          When walking with arrow to Meat, it gets unchecked
      3 - When node is collapsed and checked thru keyboard (space)
         the middle state is possible which should not
      Here is joined an animated gif showing the 3 problems
      Thanks for your advices

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends i am new to autoit and i am stuck in middle of automation of flashing tool..
      my requirement is i have a window and i have to get the value present in that window (below is the picture)

      in the above window i need to get the value of the highlighted field.the value of this filed keeps on changing...ii need to get the current value present in the field..below are the details of the window and field..

      CAN it be done?

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys i am working on automating a flashing tool..When flashing is started if there is any error in connection it pops's up a error window...(as shown below)

       whenever this popup appears i need a msgbox to appear saying "error occured" how can i do this?


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.