Jump to content

Switch GUI button


Recommended Posts

How do I make a GUI Button a switchable button. I am wanting a button to say "Pause" and when it's clicked it pauses and then says "resume" thus allowing for resuming.

$scriptName = @ScriptFullPath

autoStartProgressBar($scriptName)

Func autoStartProgressBar($scriptName)
    GUICreate(StringTrimRight(@ScriptName,4),300,160, -1,-1, $WS_CAPTION, $WS_EX_TOPMOST) 
    ;GUICreate(StringTrimRight(@ScriptName,4),220,100, -1,-1, $WS_MINIMIZEBOX + $WS_GROUP + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU, $WS_EX_TOPMOST) ;GUICreate(StringTrimRight(@ScriptName,4),220,100, -1,-1, -1, $WS_EX_TOPMOST) ;GUISetBkColor (0xE0FFFF)

    GUICtrlCreateLabel ('Automated Process will run in 3 seconds. Please do not use the keyboard or mouse!', 5,5,290,40,$SS_CENTER) 
    $progressbar = GUICtrlCreateProgress (45,55,200,20,$PBS_SMOOTH) 
    $procent = GUICtrlCreateLabel ('0 %', 45,90,200,20,$SS_CENTER) 
    $stop = GUICtrlCreateButton ("Stop",110,115,70,22,$BS_DEFPUSHBUTTON)
    $pause = GUICtrlCreateButton ("Pause",200,115,70,22,$BS_DEFPUSHBUTTON)

    GUISetState()
    $i = 0
    $s = -1
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $stop OR $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
    
        $i = $i + 1
        If $i > 100 Then $i = 0
        GUICtrlSetData ($progressbar,$i)
        GUICtrlSetData ($procent,$i & ' %')
        
        Sleep(100)
    Wend
EndFunc
A decision is a powerful thing
Link to comment
Share on other sites

ANSWER

I don't know if this is the best idea, but it works.

$scriptName = @ScriptName

autoStartProgressBar($scriptName)

Func autoStartProgressBar($scriptName)
    GUICreate(StringTrimRight($scriptName,4),300,160, -1,-1, $WS_CAPTION, $WS_EX_TOPMOST) 
    ;GUICreate(StringTrimRight(@ScriptName,4),220,100, -1,-1, $WS_MINIMIZEBOX + $WS_GROUP + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU, $WS_EX_TOPMOST) 
    ;GUICreate(StringTrimRight(@ScriptName,4),220,100, -1,-1, -1, $WS_EX_TOPMOST) 

    GUICtrlCreateLabel ('Automated Process will run soon. Please do not use the keyboard or mouse!', 5,5,290,40,$SS_CENTER) 
    $progressbar = GUICtrlCreateProgress (45,55,200,20,$PBS_SMOOTH) 
    $procent = GUICtrlCreateLabel ('0 %', 45,90,200,20,$SS_CENTER) 
    $stop = GUICtrlCreateButton ("Stop",60,125,70,22,$BS_DEFPUSHBUTTON)
    $pause = GUICtrlCreateButton ("Pause",175,125,70,22,$BS_DEFPUSHBUTTON)

    GUISetState()
    $i = 0
    $state = "Resumed"
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $stop OR $msg = $GUI_EVENT_CLOSE Then Exit
        
        
        If $state = "Resumed" Then
            If $msg = $pause Then 
                GUICtrlSetData($pause,"Resume")
                $state = "Paused"
            EndIf
            $i = $i + 1
            GUICtrlSetData ($progressbar,$i)
            GUICtrlSetData ($procent,$i & ' %')
        ElseIf $state = "Paused" Then
            If $msg = $pause Then
                GUICtrlSetData($pause,"Pause")
                $state = "Resumed"
            EndIf
        EndIf
        
        If $i > 100 Then 
            $i = 0
            ExitLoop
        EndIf
        
        
        Sleep(100)
    Wend
EndFunc
A decision is a powerful thing
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...