Jump to content

How to interrupt GUI Event?


meisu
 Share

Recommended Posts

Hello, I wrote a script, a simply counter.

When I pressed the "OK" button, counter was started.

My question is:

How could I stop counter(it is working..) when I pressed the "STOP" button?

What function that I can use..?

Thanks for your help!!

The Code of counter is below:

--------------------------------------------------------------------------------------------------

#include<GUIConstants.au3>

GUICreate("Hello World!!",250,120)

GUISetState(@SW_SHOW)

$okbutton=GUICtrlCreateButton("OK",60,70,60)

$stopbutton=GUICtrlCreateButton("STOP",130,70,60)

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $okbutton

$i = 1

While $i <11

Sleep(1000)

GUICtrlCreateLabel ("Time Count:",55,35)

GUICtrlCreateLabel ($i,115,35)

GUISetState (@SW_SHOW)

$i = $i + 1

WEnd

Case $msg = $stopbutton

; ???

Case $msg = $GUI_EVENT_CLOSE

----------------------------------------------------------------------------------------------------

Link to comment
Share on other sites

more like this

#include<GUIConstants.au3>

Dim $i = 0, $t = 0, $dif, $begin

GUICreate("Hello World!!", 250, 120)
GUICtrlCreateLabel("Time Count:", 55, 35)
$time = GUICtrlCreateLabel("   ", 125, 35)
$okbutton = GUICtrlCreateButton("OK", 60, 70, 60)
$stopbutton = GUICtrlCreateButton("STOP", 130, 70, 60)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $okbutton
            $t = 1
            $i = 0
            $begin = TimerInit()
        Case $msg = $stopbutton
            $t = 0
            
        Case $msg = $GUI_EVENT_CLOSE
    EndSelect
    
    $dif = TimerDiff($begin)
    If $t = 1 And $dif >= 1000 Then
        $i = $i + 1
        GUICtrlSetData($time, $i)
        $begin = TimerInit()
    EndIf

WEnd

8)

NEWHeader1.png

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...