Jump to content

Recommended Posts

Posted

Hello,

 

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

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted (edited)

What do you have in mind when you request another way? What doesn't look good enough?

This might be another way:

#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($Ctrl)
        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
            $aInfo = CheckboxInfo($Ctrl)
            ConsoleWrite('Checked: ' & $aInfo[0] & @CRLF)
        Case $BtnCheckEnabled
            $aInfo = CheckboxInfo($Ctrl)
            ConsoleWrite('Enabled: ' & $aInfo[1] & @CRLF)
        Case $BtnCheckHidden
            $aInfo = CheckboxInfo($Ctrl)
            ConsoleWrite('Visible: ' & $aInfo[2] & @CRLF)
    EndSwitch
WEnd


Func CheckboxInfo($CtrlID)
    Local $aInfo[3]
    $aInfo[0] = (GUICtrlRead($CtrlID) = $GUI_CHECKED)                           ; IsChecked -> True/False
    $aInfo[1] = (BitAND(GUICtrlGetState($CtrlID),$GUI_ENABLE) = $GUI_ENABLE)    ; IsEnable  -> True/False
    $aInfo[2] = (BitAND(GUICtrlGetState($CtrlID),$GUI_SHOW) = $GUI_SHOW)        ; IsVisible -> True/False
    Return $aInfo
EndFunc

 

Edited by Andreik
Posted

Hi.

Returning a result array is a good idea, thx.

 

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
×
×
  • Create New...