lsq726 发表于 2010-9-8 00:50:12

求助怎么可以按下按钮取消正在执行的循环?[已经解决谢谢3M]

本帖最后由 lsq726 于 2010-9-8 19:39 编辑

如下面的这个代码。
按下 开始任务 按钮 进行一个循环
怎么可以按下 取消任务 中断循环#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\My Documents\aaa.kxf
$Form1 = GUICreate("Form1", 438, 211, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Label1 = GUICtrlCreateLabel("", 16, 36, 164, 28)
GUICtrlSetOnEvent(-1, "Label1Click")
$Button1 = GUICtrlCreateButton("开始任务", 216, 32, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("取消任务", 216, 80, 75, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(100)
WEnd

Func Button1Click()
        For $t=20 To 0 Step -1
               
       
        Sleep(1000)
        GUICtrlSetData($Label1, $t&"秒后重新启动计算机")

        If $t=0 Then
                Run(@ComSpec & " /c " & 'shutdown -i', "", @SW_HIDE)
        EndIf
       
Next


EndFunc
Func Button2Click()
       

EndFunc
Func Form1Close()

EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func Label1Click()

EndFunc

3mile 发表于 2010-9-8 10:25:38

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\My Documents\aaa.kxf
$Form1 = GUICreate("Form1", 438, 211, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Label1 = GUICtrlCreateLabel("", 16, 36, 164, 28)
GUICtrlSetOnEvent(-1, "Label1Click")
$Button1 = GUICtrlCreateButton("开始任务", 216, 32, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("取消任务", 216, 80, 75, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $t

While 1
        Sleep(100)
WEnd

Func Button1Click()
        $t=20
        AdlibRegister("set",1000)
EndFunc   ;==>Button1Click

Func Button2Click()
        AdlibUnRegister("set")
        MsgBox(4096,"","用户取消")
EndFunc   ;==>Button2Click

Func set()
        GUICtrlSetData($Label1, $t & "秒后重新启动计算机")
        If $t < 1 Then
                Run(@ComSpec & " /c " & 'shutdown -i', "", @SW_HIDE)
        EndIf       
        $t-=1
EndFunc

Func Form1Close()

EndFunc   ;==>Form1Close
Func Form1Maximize()

EndFunc   ;==>Form1Maximize
Func Form1Minimize()

EndFunc   ;==>Form1Minimize
Func Form1Restore()

EndFunc   ;==>Form1Restore
Func Label1Click()

EndFunc   ;==>Label1Click

lsqyx528 发表于 2010-9-8 11:34:39

顶你。。。。。

catcher 发表于 2010-9-8 14:53:08

哈哈,学习了,需要这个

yingf20 发表于 2010-9-9 10:51:00

很有学习价值
页: [1]
查看完整版本: 求助怎么可以按下按钮取消正在执行的循环?[已经解决谢谢3M]