本帖最后由 thackit 于 2012-7-2 15:24 编辑
想在执行脚本的同时,点击一个按钮来中止脚本执行。
我分别试验了消息模式和事件模式两种方案,但是当点击“开始听课”按钮脚本正在执行时,想通过点击“停止听课”按钮来中止脚本都没有反应。
代码如下:
消息模式:GUICreate($name, 220, 750)
$Button1 = GUICtrlCreateButton("开始听课", 25, 640, 100, 50)
$Button5 = GUICtrlCreateButton("停止听课", 135, 650, 65, 30)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
autolesson1()
Case $msg = $Button5
If MsgBox( 4097, "提示", "确定停止听课?") Then Exit
EndSelect
WEnd
事件模式:GUICreate($name, 220, 750)
$Button1 = GUICtrlCreateButton("开始听课", 25, 640, 100, 50)
$Button5 = GUICtrlCreateButton("停止听课", 135, 650, 65, 30)
GUISetState()
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button1, "gui")
GUICtrlSetOnEvent($Button5, "killself")
While 1
;;;
WEnd
Exit
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
autolesson1()
EndSwitch
EndFunc
Func killself()
If MsgBox( 4097, "提示", "确定停止听课?") Then Exit
EndFunc
|