Jump to content

Click box clicked, then press (button) and run rest of script?


xShadowx
 Share

Recommended Posts

I have been messing around with click boxes, but how would I make it so when I have the click box clicked and I press a (button) it will run a run command?

I couldnt figure it out. All help is appreciated.

$Msg = GuiGetMsg()

Switch $Msg
  Case $btn1
    if GuiCtrlRead($ChkBox1) = $GUI_CHECKED then Run("....
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.
Link to comment
Share on other sites

xShadowx

Should to check so:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("Test", 200, 100)

$checkbox = GUICtrlCreateCheckbox("Check me", 50, 25, 70, 15)

$button = GUICtrlCreateButton("Test", 65, 66, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            If BitAND(GUICtrlRead($checkbox), $GUI_CHECKED) Then
                ConsoleWrite("Checked" & @LF)
            Else
                ConsoleWrite("Unchecked" & @LF)
            EndIf
    EndSwitch
WEnd

Because the checkbox might have several states :mellow:

Link to comment
Share on other sites

xShadowx

Should to check so:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("Test", 200, 100)

$checkbox = GUICtrlCreateCheckbox("Check me", 50, 25, 70, 15)

$button = GUICtrlCreateButton("Test", 65, 66, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            If BitAND(GUICtrlRead($checkbox), $GUI_CHECKED) Then
                ConsoleWrite("Checked" & @LF)
            Else
                ConsoleWrite("Unchecked" & @LF)
            EndIf
    EndSwitch
WEnd

Because the checkbox might have several states :mellow:

Yes it could, and I've even told other people about that. Thanks rasim.
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.
Link to comment
Share on other sites

Could I add multiple $""'s to it? Like:

GUICtrlRead($checkbox, $checkbox1, $checkbox2)

I have tryed using "," and "&".

No, but if you have many checkbox controls, you can create a array with this controls and then check state of the each control in the loop. :mellow:
Link to comment
Share on other sites

As an array, do you mean having multiple of this?

Case $button
            If BitAND(GUICtrlRead($checkbox), $GUI_CHECKED) Then
                ConsoleWrite("Checked" & @LF)
            Else
                ConsoleWrite("Unchecked" & @LF)
            EndIf
Link to comment
Share on other sites

xShadowx

Example:

#include <GuiConstantsEx.au3>

Dim $aCheckBox[10]
Dim $left = 10, $right = 10

$hGUI = GUICreate("Test", 420, 160)

For $i = 0 To UBound($aCheckBox) - 1
    $aCheckBox[$i] = GUICtrlCreateCheckbox("Checkbox" & $i + 1, $left, $right, 80, 15)
    $left += 80
    
    If $left >= 400 Then
        $left = 10
        $right += 20
    EndIf
Next

$CheckButton = GUICtrlCreateButton("Test", 11, 128, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CheckButton
            _CheckedGet($aCheckBox)
    EndSwitch
WEnd

Func _CheckedGet($aControl)
    Local $i
    
    For $i = 0 To UBound($aControl) - 1
        ConsoleWrite(GUICtrlRead($aControl[$i], 1) & " is checked: " & (BitAND(GUICtrlRead($aControl[$i]), $GUI_CHECKED) = $GUI_CHECKED) & @LF)
    Next
EndFunc
Link to comment
Share on other sites

xShadowx

Hi. Your questions is very base and I am surprised why you can't find examples in the help file :mellow:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("Test", 200, 100)

$Calc_checkbox = GUICtrlCreateCheckbox("Calc", 11, 11, 50, 15)
$Notepad_checkbox = GUICtrlCreateCheckbox("Notepad", 11, 36, 60, 15)
$Regedit_checkbox = GUICtrlCreateCheckbox("Regedit", 11, 61, 65, 15)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Calc_checkbox
            If BitAND(GUICtrlRead($Calc_checkbox), $GUI_CHECKED) Then Run("calc.exe")
        Case $Notepad_checkbox
            If BitAND(GUICtrlRead($Notepad_checkbox), $GUI_CHECKED) Then Run("notepad.exe")
        Case $Regedit_checkbox
            If BitAND(GUICtrlRead($Regedit_checkbox), $GUI_CHECKED) Then Run("regedit.exe")
    EndSwitch
WEnd
Link to comment
Share on other sites

Thank you rasim, that worked perfectly. Now one question, I can use "GUI_UNCHECKED" as well, now how would I create an error if all of the boxes are unclicked. I have tryed messing around with it. I get an error once I get past $2, and its because of "BitAND".

If BitAND(GUICtrlRead($1, $2), $GUI_UNCHECKED) Then Run("regedit.exe")

Now is there a way to link all of the "$1, $2..." into one? Like This?

$all = ($1, $2, $3, $4)

I have been playing around with it, but I couldnt find out. Its probably something simple too. :mellow:

Edited by xShadowx
Link to comment
Share on other sites

xShadowx

If BitAND(GUICtrlRead($1), $GUI_CHECKED) And BitAND(GUICtrlRead($2), $GUI_CHECKED) Then
    MsgBox(0, "MyProgram", "All checkboxs are checked")
Else
    MsgBox(16, "MyProgram error", "Some checkboxs are not checked")
EndIf
I suppose you could have this to make it more compact, though it might look a bit strange.

If BitAND(GUICtrlRead($1),GUICtrlRead($2),GUICtrlRead($3),GUICtrlRead($4), $GUI_CHECKED) Then
    MsgBox(0, "MyProgram", "All checkboxs are checked")
Else
    MsgBox(16, "MyProgram error", "Some checkboxs are not checked")
EndIf
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.
Link to comment
Share on other sites

I suppose you could have this to make it more compact, though it might look a bit strange.

If BitAND(GUICtrlRead($1),GUICtrlRead($2),GUICtrlRead($3),GUICtrlRead($4), $GUI_CHECKED) Then
    MsgBox(0, "MyProgram", "All checkboxs are checked")
Else
    MsgBox(16, "MyProgram error", "Some checkboxs are not checked")
EndIf
Yes, you are right, good and simple example :mellow:
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...