Multi - GUICtrlSetState

  • Edit:
    Braucht wohl niemand, ich füge aber unten trotzdem mal 2 neue Versionen hinzu. eine mit #include <Array.au3>, die andere basiert auf StringSplit.
    =========

    Hey, ich habe eine kleine Funktion geschrieben, welche es einem erlaubt,
    bis zu 10 Steuerelemente (erweiterbar) auf einmal für GUICtrlSetState ( controlID, state ) aufzurufen.
    Z.B
    4 Button deaktivieren und wieder aktivieren.

    _MultiGSetState("D", $Button1, $Button2, $Button3, $Button4)
    Sleep(5000)
    _MultiGSetState("E", $Button1, $Button2, $Button3, $Button4)

    Möglich sind die Aufrufe:
    "Show" - "Hide" - "Enable" - "Disable" - "CHECKED" - "UNCHECKED"
    oder die Kurzform
    "S" - "H" - "E" - "D" - "CH" - "UN"

    Man könnte auch einfach die Hilfsfunktion __GSetState() aufrufen, dann aber z.B. so __GSetState($GUI_DISABLE, $Button1, $Button2, $Button3, $Button4)

    Ich hoffe, das es jemand nützlich findet.

    so long
    Frank

    Spoiler anzeigen
    [autoit]

    ;==========================================================================================
    ; Function : _MultiGSetState( state, controlID_1....controlID_10)
    ; Description : Changes the state of a control. / GUICtrlSetState
    ; Author : Thunder-man (Frank Michalski)
    ; Date - Version : 21. September 2007 - V 1.00
    ; Parameter : state = "Show" - "Hide" - "Enable" - "Disable" - "CHECKED" - "UNCHECKED"
    ; Example : : Enable four Button
    ; _MultiGSetState("E", $Button1, $Button2, $Button3, $Button4)
    ;==========================================================================================
    Func _MultiGSetState($sGState , $ID1="", $ID2="", $ID3="", $ID4="", $ID5="", $ID6="", $ID7="", $ID8="", $ID9="", $ID10="")
    Local $0
    Switch $sGState
    Case $sGState = "Show" or $sGState = "S"
    $0 = __GSetState($GUI_SHOW, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case $sGState = "Hide" or $sGState = "H"
    $0 = __GSetState($GUI_HIDE, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case $sGState = "Enable" or $sGState = "E"
    $0 = __GSetState($GUI_ENABLE, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case $sGState = "Disable" or $sGState = "D"
    $0 = __GSetState($GUI_DISABLE, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case $sGState = "CHECKED" or $sGState = "CH"
    $0 = __GSetState($GUI_CHECKED, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case $sGState = "UNCHECKED" or $sGState = "UN"
    $0 = __GSetState($GUI_UNCHECKED, $ID1, $ID2, $ID3, $ID4, $ID5, $ID6, $ID7, $ID8, $ID9, $ID10)
    Case Else
    $0 = $sGState
    EndSwitch
    Return $0
    EndFunc
    Func __GSetState($s_GState,$ID_1="",$ID_2="",$ID_3="",$ID_4="",$ID_5="",$ID_6="",$ID_7="",$ID_8="",$ID_9="",$ID_10="")
    ;...It is used from _MultiGSetState()...; "Changes the state of a control"...; By Thunder-man
    Local $sState
    If Not $ID_1 = "" Then GUICtrlSetState($ID_1 , $s_GState)
    If Not $ID_2 = "" Then GUICtrlSetState($ID_2 , $s_GState)
    If Not $ID_3 = "" Then GUICtrlSetState($ID_3 , $s_GState)
    If Not $ID_4 = "" Then GUICtrlSetState($ID_4 , $s_GState)
    If Not $ID_5 = "" Then GUICtrlSetState($ID_5 , $s_GState)
    If Not $ID_6 = "" Then GUICtrlSetState($ID_6 , $s_GState)
    If Not $ID_7 = "" Then GUICtrlSetState($ID_7 , $s_GState)
    If Not $ID_8 = "" Then GUICtrlSetState($ID_8 , $s_GState)
    If Not $ID_9 = "" Then GUICtrlSetState($ID_9 , $s_GState)
    If Not $ID_10 = "" Then GUICtrlSetState($ID_10 , $s_GState)
    EndFunc
    ;==========================================================================================

    [/autoit]


    Array Version:
    Die Anzahl der Control´s ist nun nur durch dem Array begrenzt (21)

    Beispiel:
    #include <Array.au3>
    _MultiGSetState("D", _ArrayCreate($los, $Btn_switch, $Btn_Entry, $Btn_save_all))

    Spoiler anzeigen
    [autoit]

    ;==========================================================================================
    ; Function : _MultiGSetState("state", _ArrayCreate( controlID_1, controlID_2 ...))
    ; Description : Changes the state of a control. / GUICtrlSetState
    ; Author : Thunder-man (Frank Michalski)
    ; Date - Version : 24. September 2007 - V 1.00 A
    ; Parameter : state = "Show" - "Hide" - "Enable" - "Disable" - "CHECKED" - "UNCHECKED"
    ; Example : : Enable four Button
    ; _MultiGSetState("E", _ArrayCreate($Button1, $Button2, $Button3, $Button4))
    ;==========================================================================================
    Func _MultiGSetState($sGState, $GUICArr)
    Local $0
    Switch $sGState
    Case $sGState = "Show" or $sGState = "S"
    $0 = __GSetState($GUI_SHOW, $GUICArr)
    Case $sGState = "Hide" or $sGState = "H"
    $0 = __GSetState($GUI_HIDE, $GUICArr)
    Case $sGState = "Enable" or $sGState = "E"
    $0 = __GSetState($GUI_ENABLE, $GUICArr)
    Case $sGState = "Disable" or $sGState = "D"
    $0 = __GSetState($GUI_DISABLE, $GUICArr)
    Case $sGState = "CHECKED" or $sGState = "CH"
    $0 = __GSetState($GUI_CHECKED, $GUICArr)
    Case $sGState = "UNCHECKED" or $sGState = "UN"
    $0 = __GSetState($GUI_UNCHECKED, $GUICArr)
    Case Else
    $0 = $sGState
    EndSwitch
    Return $0
    EndFunc
    Func __GSetState($sGState, $GUICArr)
    ;...It is used from _MultiGSetState()...; "Changes the state of a control"...; By Thunder-man
    Local $state = $sGState
    For $i=0 to UBound($GUICArr) -1 Step 1
    GuiCtrlSetState( $GUICArr[$i], $state)
    Next
    EndFunc
    ;==========================================================================================

    [/autoit]

    StringSplit Version:
    Allerdings ist der Aufruf der Funktion anders.
    Es wird der Rückgabe Wert der controlID übergeben.
    z.B
    $Button1 = GUICtrlCreateButton("Übernehmen", 112, 301, 73, 25, 0)
    Rückgabewert: (ID)
    MsgBox(64, "", $Button1)
    Oder mit Au3Info ermitteln.

    Dann z.B 5 Control Elemente disabeln
    _MultiGSetState("D", "10, 12, 15, 26, 27")

    Spoiler anzeigen
    [autoit]

    ;==========================================================================================
    ; Function : _MultiGSetState("state", "controlID_1, controlID_2, controlID_2")
    ; Description : Changes the state of a control. / GUICtrlSetState
    ; Author : Thunder-man (Frank Michalski)
    ; Date - Version : 24. September 2007 - V 1.00 S
    ; Parameter : state = "Show" - "Hide" - "Enable" - "Disable" - "CHECKED" - "UNCHECKED"
    ; Example : : Enable four Button
    ; _MultiGSetState("E", "10, 12, 15, 26, 27")
    ;==========================================================================================
    Func _MultiGSetState($sGState, $GUICSplitt)
    Local $0
    Switch $sGState
    Case $sGState = "Show" or $sGState = "S"
    $0 = __GSetState($GUI_SHOW, $GUICSplitt)
    Case $sGState = "Hide" or $sGState = "H"
    $0 = __GSetState($GUI_HIDE, $GUICSplitt)
    Case $sGState = "Enable" or $sGState = "E"
    $0 = __GSetState($GUI_ENABLE, $GUICSplitt)
    Case $sGState = "Disable" or $sGState = "D"
    $0 = __GSetState($GUI_DISABLE, $GUICSplitt)
    Case $sGState = "CHECKED" or $sGState = "CH"
    $0 = __GSetState($GUI_CHECKED, $GUICSplitt)
    Case $sGState = "UNCHECKED" or $sGState = "UN"
    $0 = __GSetState($GUI_UNCHECKED, $GUICSplitt)
    Case Else
    $0 = $sGState
    EndSwitch
    Return $0
    EndFunc
    Func __GSetState($sGState, $GUICSplitt)
    ;~ ;...It is used from _MultiGSetState()...; "Changes the state of a control"...; By Thunder-man
    Local $state = $sGState
    $Splitt = StringSplit($GUICSplitt, ",")
    For $i=1 to $Splitt[0] step 1
    GUICtrlSetState($Splitt[$i], $state)
    Next
    EndFunc
    ;==========================================================================================

    [/autoit]

    Einmal editiert, zuletzt von thunder-man (24. September 2007 um 23:50)

  • Hallo Thunder-Man.

    Nette Sachen.

    Du schreibst: "Allerdings ist der Aufruf der Funktion anders."

    Wäre sehr schön, wenn Du evtl. kleine Bsp. beifügen würdest, wo die Funktionen einfach dargestellt werden.
    Anfänger werden sonst Probleme bekommen.

    Soll eine Anregung sein und kein "Gemecker".

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    k3mrwmIBHejryPvylQSFieDF5f3VOnk6iLAVBGVhKQegrFuWr3iraNIblLweSW4WgqI0SrRbS7U5jI3sn50R4a15Cthu1bEr

  • Alina
    Danke für die Anregung.

    Frage:
    Was ist der Unterschied der Array und StringSplit Function?
    Antwort:
    Für die Array Function muss die array.au3 includet werden. Wenn ich dieses aber ansonsten nicht im Script benötige steigt nur ein bisschen unnötig die
    Größe der kompilierten *.exe.

    Als Erklärung für das folgende (kleine Beispiel)
    Der Aufruf für´s Array wäre, die Variablen der Control Elemente direkt
    aufzurufen.
    _MultiGSetState("D", _ArrayCreate($Button1, $Button2))

    Bei der StringSplit Function werden die Control ID´s als "String" übergeben.
    Um diese zu ermitteln, kann man das Tool Au3Info.exe nutzen, oder wie in dem Beispiel. (Einfach mal auf die Button drücken)

    Der Aufruf: z.B. _MultiGSetState("D", "3, 4")
    Disable Button1 und Button2.

    [autoit]

    #include <GUIConstants.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Frm = GUICreate("MultiGSetState", 197, 71, 384, 218)
    $Btn_1 = GUICtrlCreateButton("Button1", 16, 40, 75, 25, 0)
    $Btn_2 = GUICtrlCreateButton("Button2", 104, 40, 75, 25, 0)
    $Btn_3 = GUICtrlCreateButton("Enable", 104, 10, 75, 25, 0)
    $Btn_4 = GUICtrlCreateButton("Disable", 16, 10, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    _MultiGSetState("D", "3, 4, 6"); Disable [Button1], [Button2] und [Button Disable]

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Btn_1
    MsgBox(64, "", 'Control ID: ' & $Btn_1)
    Case $Btn_2
    MsgBox(64, "", 'Control ID: ' & $Btn_2)
    Case $Btn_3
    _MultiGSetState("E", "3, 4, 6"); Enable [Button1], [Button2] und [Button Disable]
    _MultiGSetState("D", "5"); Disable [Button Enable]
    Case $Btn_4
    _MultiGSetState("D", "3, 4, 6"); Disable [Button1], [Button2] und [Button Disable]
    _MultiGSetState("E", "5"); Enable ]Button Enable]
    EndSwitch
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von thunder-man (25. September 2007 um 11:28)

  • also ich muß sagen, das du den beitrag sehr gut überarbeitet hast.

    hilft und ist verständlich mit den beispielen.

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    k3mrwmIBHejryPvylQSFieDF5f3VOnk6iLAVBGVhKQegrFuWr3iraNIblLweSW4WgqI0SrRbS7U5jI3sn50R4a15Cthu1bEr