Jump to content

CheckBox (Gui)


snoopy
 Share

Recommended Posts

Hellow its me again -.-

Wondering how can i make that there is only 1 choice out of 4 checkboxes

e.g. you have 4 check boxes and you cant tick them all.

in my case you can and i dont want it to be like that :).

[/autoit]
code:
#include <GUIConstants.au3>

Global $f_Run = False, $f_AnyChecked = False

Global $Form1 = GUICreate("Form1", 625, 444, 189, 146)
$Pic1 = GUICtrlCreatePic("C:\Users\Snoopy\Desktop\toontown%20awesome%20picture.jpg", 0, 0, 625, 441, 0)
GUISetState($GUI_DISABLE)
GuiCtrlSetState($pic1, $GUI_DISABLE) 
Global $Credits = GUICtrlCreateButton("Credits", 0, 0, 153, 65, 0)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global $MyButton1 = GUICtrlCreateButton("Start", 520, 0, 100, 30, 0)
GUICtrlSetFont(-1, 15, 800, 0, "MS Serif")
GUICtrlSetBkColor(-1, 0xFFFFE1)
Global $CheckBox1 = GUICtrlCreateCheckbox("Jump", 520, 32, 100, 30, 0)
Global $CheckBox2 = GUICtrlCreateCheckbox("Beg", 520, 72, 100, 30, 0)
Global $CheckBox3 = GUICtrlCreateCheckbox("Say", 520, 112, 100, 30, 0)
Global $CheckBox4 = GUICtrlCreateCheckbox("Roallover", 520, 160, 100, 30, 0)
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Credits
            MsgBox(64, "Credits", "Matthew Povolotski, Toon:Sniffy Macnose")
            
        Case $MyButton1
            HotKeySet("{F5}", "_StopIt")
            $f_Run = True
            While $f_Run
                $f_AnyChecked = False
                If BitAND(GUICtrlRead($CheckBox1), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    Local $randomcoords[7][2] = [[217,65],[228,79],[173,81],[223,93],[190,110],[214,112],[255,138]]
        MouseClick("left", 57, 45, 1)
        MouseClick("left", 127, 61, 1)
        $r = Random(0,6,1)
        MouseClick("left", $randomcoords[$r][0], $randomcoords[$r][1], 1)
        EndIf
                If BitAND(GUICtrlRead($CheckBox2), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    Local $randomcoords[7][2] = [[217,75],[228,79],[173,81],[223,93],[190,110],[214,112],[255,138]]
MouseClick("left", 57, 45, 1)
MouseClick("left", 127, 61, 1)
$r = Random(0,6,1)
MouseClick("left", $randomcoords[$r][0], $randomcoords[$r][1], 1)
                EndIf
                If BitAND(GUICtrlRead($CheckBox3), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    MsgBox(64, "Checkbox 3", "CheckBox 3 is checked", 1)
                EndIf
                If BitAND(GUICtrlRead($CheckBox4), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    MsgBox(64, "Checkbox 4", "CheckBox 4 is checked", 1)
                EndIf
                If Not $f_AnyChecked Then ExitLoop
            WEnd
            HotKeySet("{F5}")
    EndSwitch
WEnd

Func _StopIt()
    $f_Run = False
EndFunc
Edited by snoopy
Link to comment
Share on other sites

This can be solved be enclosing the controls with dummys and then loop through the states using WM_COMMAND.

#include <GUIConstants.au3>
#include<WindowsConstants.au3>

Global $f_Run = False, $f_AnyChecked = False

Global $Form1 = GUICreate("Form1", 625, 444, 189, 146)
$Pic1 = GUICtrlCreatePic("C:\Users\Snoopy\Desktop\toontown%20awesome%20picture.jpg", 0, 0, 625, 441, 0)
GUISetState($GUI_DISABLE)
GuiCtrlSetState($pic1, $GUI_DISABLE)
Global $Credits = GUICtrlCreateButton("Credits", 0, 0, 153, 65, 0)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global $MyButton1 = GUICtrlCreateButton("Start", 520, 0, 100, 30, 0)
GUICtrlSetFont(-1, 15, 800, 0, "MS Serif")
GUICtrlSetBkColor(-1, 0xFFFFE1)

$checkbox_dummy_start = GUICtrlCreateDummy()
Global $CheckBox1 = GUICtrlCreateCheckbox("Jump", 520, 32, 100, 30, 0)
Global $CheckBox2 = GUICtrlCreateCheckbox("Beg", 520, 72, 100, 30, 0)
Global $CheckBox3 = GUICtrlCreateCheckbox("Say", 520, 112, 100, 30, 0)
Global $CheckBox4 = GUICtrlCreateCheckbox("Roallover", 520, 160, 100, 30, 0)
$checkbox_dummy_end = GUICtrlCreateDummy()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
           
        Case $Credits
            MsgBox(64, "Credits", "Matthew Povolotski, Toon:Sniffy Macnose")
           
        Case $MyButton1
            HotKeySet("{F5}", "_StopIt")
            $f_Run = True
            While $f_Run
                $f_AnyChecked = False
                If BitAND(GUICtrlRead($CheckBox1), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    Local $randomcoords[7][2] = [[217,65],[228,79],[173,81],[223,93],[190,110],[214,112],[255,138]]
        MouseClick("left", 57, 45, 1)
        MouseClick("left", 127, 61, 1)
        $r = Random(0,6,1)
        MouseClick("left", $randomcoords[$r][0], $randomcoords[$r][1], 1)
        EndIf
                If BitAND(GUICtrlRead($CheckBox2), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    Local $randomcoords[7][2] = [[217,75],[228,79],[173,81],[223,93],[190,110],[214,112],[255,138]]
MouseClick("left", 57, 45, 1)
MouseClick("left", 127, 61, 1)
$r = Random(0,6,1)
MouseClick("left", $randomcoords[$r][0], $randomcoords[$r][1], 1)
                EndIf
                If BitAND(GUICtrlRead($CheckBox3), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    MsgBox(64, "Checkbox 3", "CheckBox 3 is checked", 1)
                EndIf
                If BitAND(GUICtrlRead($CheckBox4), $GUI_CHECKED) Then
                    $f_AnyChecked = True
                    MsgBox(64, "Checkbox 4", "CheckBox 4 is checked", 1)
                EndIf
                If Not $f_AnyChecked Then ExitLoop
            WEnd
            HotKeySet("{F5}")
    EndSwitch
WEnd

Func _StopIt()
    $f_Run = False
EndFunc


Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ;LoWord
    Switch $iIDFrom
        Case $checkbox_dummy_start to $checkbox_dummy_end
            for $i = $checkbox_dummy_start to $checkbox_dummy_end
                if $i <> $iIDFrom then GUICtrlSetState($i,4)
            Next
    EndSwitch
EndFunc
Link to comment
Share on other sites

Like this:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $button_1, $group_1, $radio_1, $radio_2, $radio_3
    Local $radio_4, $radio_5, $radio_6, $input_1, $input_2
    Local $radioval1, $radioval2, $msg

    Opt("GUICoordMode", 1)

    GUICreate("Radio Box Grouping Demo", 400, 280)

; Create the controls
    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    $group_1 = GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    $radio_2 = GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)
        

; Set the defaults (radio buttons clicked, default button, etc)
    GUICtrlSetState($radio_1, $GUI_CHECKED)
    GUICtrlSetState($radio_6, $GUI_CHECKED)
    GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON)

; Init our vars that we will use to keep track of radio events
    $radioval1 = 0   ; We will assume 0 = first radio button selected, 2 = last button
    $radioval2 = 2

    GUISetState()

; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GUICtrlRead() at the end to read in the state of each control.  Both
; methods are equally valid
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit

            Case $msg = $button_1
                MsgBox(0, "Button", "Radio " & $radioval1)

            Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3
                $radioval1 = $msg - $radio_1

            Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6
                $radioval2 = $msg - $radio_4

        EndSelect
    WEnd
EndFunc  ;==>Example
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
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...