GUICtrlCreateCheckbox abfrage vereinfachen?

  • Hallo zusammen,

    ich habe eine Gui geschrieben wo hinter jeder Checkbox später mal ein Programm hinterlegt sein soll.
    das prinzip mit der "GUICtrlRead($Checkbox1), $GUI_CHECKED" habe ich verstanden, aber wenn ihr die source mal seht dann könnt ihr auch verstehen das die zeilen ewig lang werden wenn ich das zusammen alles verknüpfen will.
    kann man das alles etwas vereinfachen?
    so das am schluss einmal der Check für alle Checkboxen kommt, was markiert ist und was nicht und dann das entsprechende ausgeführt wird?


    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Programm Auswahl", 500, 300, -1, -1)

    [/autoit] [autoit][/autoit] [autoit]

    $Button1 = GUICtrlCreateButton("Starten", 400, 250)
    $Button2 = GUICtrlCreateButton("Exit", 450, 250)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox1 = GUICtrlCreateCheckbox("Prog1 ", 50, 50, 80)
    $Checkbox2 = GUICtrlCreateCheckbox("Prog2 ", 50, 70, 80)
    $Checkbox3 = GUICtrlCreateCheckbox("Prog3 ", 50, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox4 = GUICtrlCreateCheckbox("Prog4 ", 50, 110, 80)
    $Checkbox5 = GUICtrlCreateCheckbox("Prog5 ", 50, 130, 80)
    $Checkbox6 = GUICtrlCreateCheckbox("Prog6 ", 50, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox7 = GUICtrlCreateCheckbox("Prog7 ", 200, 50, 80)
    $Checkbox8 = GUICtrlCreateCheckbox("Prog8 ", 200, 70, 80)
    $Checkbox9 = GUICtrlCreateCheckbox("Prog9 ", 200, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox10 = GUICtrlCreateCheckbox("Prog10 ", 200, 110, 80)
    $Checkbox11 = GUICtrlCreateCheckbox("Prog11 ", 200, 130, 80)
    $Checkbox12 = GUICtrlCreateCheckbox("Prog12 ", 200, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $menu1 = GUICtrlCreateMenu("&Options")
    $menu11 = GUICtrlCreateMenuItem("Leer1", $menu1)
    $menu12 = GUICtrlCreateMenuItem("Leer2", $menu1)
    $menu13 = GUICtrlCreateMenuItem("Exit", $menu1)
    $menu2 = GUICtrlCreateMenu("&Help")
    $menu21 = GUICtrlCreateMenuItem("Info", $menu2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    ;soll aufgehen, wenn Checkbox 1, 2 und 3 ausgewählt ist und ein Button über das GUI gedrückt wird.
    If BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) And BitAnd(GUICtrlRead($Checkbox2), $GUI_CHECKED) And BitAnd(GUICtrlRead($Checkbox3), $GUI_CHECKED) then
    msgbox(0,"Prog 1, 2 und 3","Prog 1, 2 und 3")
    Exit
    ;soll aufgehen, wenn Checkbox 1 und 3 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) And BitAnd(GUICtrlRead($Checkbox3), $GUI_CHECKED) then
    Msgbox(0,"Prog 1 und 3","Prog 1 und 3")
    Exit
    ;soll aufgehen, wenn Checkbox 1 und 2 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) And BitAnd(GUICtrlRead($Checkbox2), $GUI_CHECKED) then
    msgbox(0,"Prog 1 und 2","Prog 1 und 2")
    Exit
    ;soll aufgehen, wenn Checkbox 2 und 3 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox2), $GUI_CHECKED) And BitAnd(GUICtrlRead($Checkbox3), $GUI_CHECKED) then
    msgbox(0,"Prog 2 und 3","Prog 2 und 3")
    Exit
    ;funktioniert: soll aufgehen, wenn NUR Checkbox 3 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox3), $GUI_CHECKED) then
    msgbox(0,"Prog 3","Prog 3")
    Exit
    ;funktioniert: soll aufgehen, wenn NUR Checkbox 2 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox2), $GUI_CHECKED) then
    msgbox(0,"Prog 2","Prog 2")
    Exit
    ;funktioniert: soll aufgehen, wenn NUR Checkbox 1 ausgewählt ist und ein Button über das GUI gedrückt wird.
    ElseIf BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED)then
    msgbox(0,"Prog 1","Prog 1 ")
    Exit
    Else
    msgbox(0,"Keine Software ausgewählt","Keine Software ausgewählt")
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    case $Button2
    Exit

    case $menu13
    Exit

    Case $menu21
    msgbox(0,"Infobox","Geschrieben von",5)

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; evtl. hilfsmittel

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $Radio1 = GUICtrlCreateRadio("Radio1", 8, 136, 57, 33)
    ;~ $Radio2 = GUICtrlCreateRadio("Radio2", 8, 176, 57, 41)

    [/autoit]

    Einmal editiert, zuletzt von Psyche (24. Oktober 2008 um 13:32)

  • ich würd so tun:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Programm Auswahl", 500, 300, -1, -1)

    [/autoit] [autoit][/autoit] [autoit]

    $Button1 = GUICtrlCreateButton("Starten", 400, 250)
    $Button2 = GUICtrlCreateButton("Exit", 450, 250)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox1 = GUICtrlCreateCheckbox("Prog1 ", 50, 50, 80)
    $Checkbox2 = GUICtrlCreateCheckbox("Prog2 ", 50, 70, 80)
    $Checkbox3 = GUICtrlCreateCheckbox("Prog3 ", 50, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox4 = GUICtrlCreateCheckbox("Prog4 ", 50, 110, 80)
    $Checkbox5 = GUICtrlCreateCheckbox("Prog5 ", 50, 130, 80)
    $Checkbox6 = GUICtrlCreateCheckbox("Prog6 ", 50, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox7 = GUICtrlCreateCheckbox("Prog7 ", 200, 50, 80)
    $Checkbox8 = GUICtrlCreateCheckbox("Prog8 ", 200, 70, 80)
    $Checkbox9 = GUICtrlCreateCheckbox("Prog9 ", 200, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox10 = GUICtrlCreateCheckbox("Prog10 ", 200, 110, 80)
    $Checkbox11 = GUICtrlCreateCheckbox("Prog11 ", 200, 130, 80)
    $Checkbox12 = GUICtrlCreateCheckbox("Prog12 ", 200, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $menu1 = GUICtrlCreateMenu("&Options")
    $menu11 = GUICtrlCreateMenuItem("Leer1", $menu1)
    $menu12 = GUICtrlCreateMenuItem("Leer2", $menu1)
    $menu13 = GUICtrlCreateMenuItem("Exit", $menu1)
    $menu2 = GUICtrlCreateMenu("&Help")
    $menu21 = GUICtrlCreateMenuItem("Info", $menu2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $line = ""
    $1 = GUICtrlRead($Checkbox1)
    $2 = GUICtrlRead($Checkbox2)
    $3 = GUICtrlRead($Checkbox3)
    $4 = GUICtrlRead($Checkbox4)
    $5 = GUICtrlRead($Checkbox5)
    $6 = GUICtrlRead($Checkbox6)
    $7 = GUICtrlRead($Checkbox7)
    $8 = GUICtrlRead($Checkbox8)
    $9 = GUICtrlRead($Checkbox9)
    $10 = GUICtrlRead($Checkbox10)
    $11 = GUICtrlRead($Checkbox11)
    $12 = GUICtrlRead($Checkbox12)


    if $1 = 1 Then $line = $line & "prog 1 "
    if $2 = 1 Then $line = $line & "prog 2 "
    if $3 = 1 Then $line = $line & "prog 3 "
    if $4 = 1 Then $line = $line & "prog 4 "
    if $5 = 1 Then $line = $line & "prog 5 "
    if $6 = 1 Then $line = $line & "prog 6 "
    if $7 = 1 Then $line = $line & "prog 7 "
    if $8 = 1 Then $line = $line & "prog 8 "
    if $9 = 1 Then $line = $line & "prog 9 "
    if $10 = 1 Then $line = $line & "prog 10 "
    if $11 = 1 Then $line = $line & "prog 11 "
    if $12 = 1 Then $line = $line & "prog 12 "


    MsgBox(64, "", $line)


    case $Button2
    Exit

    case $menu13
    Exit

    Case $menu21
    msgbox(0,"Infobox","Geschrieben von",5)

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; evtl. hilfsmittel

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $Radio1 = GUICtrlCreateRadio("Radio1", 8, 136, 57, 33)
    ;~ $Radio2 = GUICtrlCreateRadio("Radio2", 8, 176, 57, 41)

    [/autoit]

    ---
    In "Independence Day" konnten die Windows-Erdcomputer problemlos mit denen der Außerirdischen kommunizieren. Was sagt uns das über unseren lieben Bill Gates? :D
    ---

  • ich so:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Programm Auswahl", 500, 300, -1, -1)

    [/autoit] [autoit][/autoit] [autoit]

    $Button1 = GUICtrlCreateButton("Starten", 400, 250)
    $Button2 = GUICtrlCreateButton("Exit", 450, 250)
    Dim $checkbox[12], $read[12]
    $Checkbox[0] = GUICtrlCreateCheckbox("Prog1 ", 50, 50, 80)
    $Checkbox[1] = GUICtrlCreateCheckbox("Prog2 ", 50, 70, 80)
    $Checkbox[2] = GUICtrlCreateCheckbox("Prog3 ", 50, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[3] = GUICtrlCreateCheckbox("Prog4 ", 50, 110, 80)
    $Checkbox[4] = GUICtrlCreateCheckbox("Prog5 ", 50, 130, 80)
    $Checkbox[5] = GUICtrlCreateCheckbox("Prog6 ", 50, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[6] = GUICtrlCreateCheckbox("Prog7 ", 200, 50, 80)
    $Checkbox[7] = GUICtrlCreateCheckbox("Prog8 ", 200, 70, 80)
    $Checkbox[8] = GUICtrlCreateCheckbox("Prog9 ", 200, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[9] = GUICtrlCreateCheckbox("Prog10 ", 200, 110, 80)
    $Checkbox[10] = GUICtrlCreateCheckbox("Prog11 ", 200, 130, 80)
    $Checkbox[11] = GUICtrlCreateCheckbox("Prog12 ", 200, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $menu1 = GUICtrlCreateMenu("&Options")
    $menu11 = GUICtrlCreateMenuItem("Leer1", $menu1)
    $menu12 = GUICtrlCreateMenuItem("Leer2", $menu1)
    $menu13 = GUICtrlCreateMenuItem("Exit", $menu1)
    $menu2 = GUICtrlCreateMenu("&Help")
    $menu21 = GUICtrlCreateMenuItem("Info", $menu2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    For $i = 0 To Ubound($Checkbox)-1
    $read[$i] = GUICtrlRead($Checkbox[$i])
    if $read[$i] = 1 Then $line &= "prog "&$i+1
    Next
    MsgBox(64, "", $line)


    case $Button2
    Exit

    case $menu13
    Exit

    Case $menu21
    msgbox(0,"Infobox","Geschrieben von",5)

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; evtl. hilfsmittel

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $Radio1 = GUICtrlCreateRadio("Radio1", 8, 136, 57, 33)
    ;~ $Radio2 = GUICtrlCreateRadio("Radio2", 8, 176, 57, 41)

    [/autoit]

    MFG FireFlyer

    *Paradox ist, wenn man sich im Handumdrehen den Fuss bricht* :D

  • Oder:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Programm Auswahl", 500, 300, -1, -1)

    [/autoit] [autoit][/autoit] [autoit]

    $Button1 = GUICtrlCreateButton("Starten", 400, 250)
    $Button2 = GUICtrlCreateButton("Exit", 450, 250)
    Dim $checkbox[12], $read[12]
    $Checkbox[0] = GUICtrlCreateCheckbox("Prog1 ", 50, 50, 80)
    $Checkbox[1] = GUICtrlCreateCheckbox("Prog2 ", 50, 70, 80)
    $Checkbox[2] = GUICtrlCreateCheckbox("Prog3 ", 50, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[3] = GUICtrlCreateCheckbox("Prog4 ", 50, 110, 80)
    $Checkbox[4] = GUICtrlCreateCheckbox("Prog5 ", 50, 130, 80)
    $Checkbox[5] = GUICtrlCreateCheckbox("Prog6 ", 50, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[6] = GUICtrlCreateCheckbox("Prog7 ", 200, 50, 80)
    $Checkbox[7] = GUICtrlCreateCheckbox("Prog8 ", 200, 70, 80)
    $Checkbox[8] = GUICtrlCreateCheckbox("Prog9 ", 200, 90, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $Checkbox[9] = GUICtrlCreateCheckbox("Prog10 ", 200, 110, 80)
    $Checkbox[10] = GUICtrlCreateCheckbox("Prog11 ", 200, 130, 80)
    $Checkbox[11] = GUICtrlCreateCheckbox("Prog12 ", 200, 150, 80)

    [/autoit] [autoit][/autoit] [autoit]

    $menu1 = GUICtrlCreateMenu("&Options")
    $menu11 = GUICtrlCreateMenuItem("Leer1", $menu1)
    $menu12 = GUICtrlCreateMenuItem("Leer2", $menu1)
    $menu13 = GUICtrlCreateMenuItem("Exit", $menu1)
    $menu2 = GUICtrlCreateMenu("&Help")
    $menu21 = GUICtrlCreateMenuItem("Info", $menu2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $Button2, $menu13
    Exit
    Case $Button1
    For $i = 0 To Ubound($Checkbox)-1
    if _IsChecked($Checkbox[$i]) Then $line &= "prog "&$i+1
    Next
    MsgBox(64, "", $line)
    Case $menu21
    msgbox(0,"Infobox","Geschrieben von",5)

    EndSwitch
    WEnd
    Func _IsChecked($box)
    Return ( BitAND(GUICtrlRead($box), $GUI_CHECKED) = $GUI_CHECKED)
    EndFunc

    [/autoit]