EpicKnarvik97
EpicKnarvik97

Reputation: 165

Autoit make button do two things. One every other click

I have this code:

        If $servers = "RUNNING" Then
            GUISwitch($GUI)
            GUISetState(@SW_SHOW, $GUI)
        Else
            MsgBox(16, "Failure", "The server isn't running")
        EndIf

        If $servers = "RUNNING" Then
            GUISwitch($GUI)
            GUISetState(@SW_HIDE, $GUI)
        Else
            MsgBox(16, "Failure", "The server isn't running")
        EndIf

One will show a GUI and the other will hide the GUI. I have a button which is supposed to do one or another of them. How can I make the button to one or another every other time? Something like if the gui is hidden, then show. If it's shown, then hide.

Upvotes: 1

Views: 1636

Answers (1)

Xenobiologist
Xenobiologist

Reputation: 2151

#Region    ;************ Includes ************
#Include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.8.1
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

; example 1
Example1()
Func Example1()
    Local $msg

    $GUI = GUICreate("My GUI") ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW) ; will display an empty dialog box
    $b = GUICtrlCreateButton('switch State', 10, 10, 100, 20)

        $GUI2 = GUICreate("CHILD", 110, 10, 100, 20) ; will create a dialog box that when displayed is centered

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        If $msg = $b Then
            If BitAND(WinGetState($GUI2), 2) Then
                GUISetState(@SW_HIDE, $GUI2)
            Else
                GUISetState(@SW_SHOW, $GUI2)
            EndIf
        EndIf

    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Upvotes: 2

Related Questions