Sign in to follow this  
Followers 0
yarsye

How to stop/pause GUI script while the script function is running

6 posts in this topic

#1 ·  Posted (edited)

GUI script

While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            Button1_func()
        Case $Button2
            Exit

Func Button1_func()
;The function will run a applicaton for a long time.
EndFunc

How can I stop/pasue the script when click $Button2.

Now the problem I encountered was when I click $Button2 after $Button1, $Button2 has no effect, it run well if click $Button2 only, I thought it's the Button1_func() was still running casued, how can I stop/pause the script?

Edited by yarsye

Share this post


Link to post
Share on other sites



Look up hotkeyset() in the help file.

It will be called when you press a button.

If you don't want the hotkey, you have to add a check inside the button1 function to see if button 2 was hit.


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't want the hotkey.

I want the one button to Start and another to Stop, it's difficult to add a check in the Button1_func(), the function will call many other functions. So I want to use a function to Button1_func() when clicking Button2, just like

While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            Button1_func()
        Case $Button2
            StopButton1_fun()
            Exit

Whether my idea is realizable? How can stop a function while it's running?

Edited by yarsye

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Edit

Yeah. I can't find any other way to do it unless you check to see if button2 was pressed within the function.

Edited by Coolw

My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

check up "GUI OnEvent Mode" in the help file.

With that when you press Button 2, it will "interrupt" the first function.

Share this post


Link to post
Share on other sites

Could do somthing like this, but its untested just giving you an idea.

While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            $Pause = 1
                 While $Pause = 1
                        sleep(100)
                  Wend
        Case $Button2
            $Pause = 0
Wend

Share this post


Link to post
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
Sign in to follow this  
Followers 0