#include <GUIConstantsEx.au3>
;~ Opt("GUIOnEventMode", 1)
Opt('TrayMenuMode', 1)
HotKeySet("{F8}", "StartEvt")
HotKeySet("{F7}", "PauseEvt")
$Form1_1 = GUICreate("GUI测试", 230, 120, 192, 60)
$StartBtn = GUICtrlCreateButton("开始(F8)", 20, 40, 81, 30)
;~ GUICtrlSetOnEvent(-1, "StartEvt")
$PauseBtn = GUICtrlCreateButton("暂停(F7)", 132, 40, 81, 30)
;~ GUICtrlSetOnEvent(-1, "PauseEvt")
GUICtrlSetState($PauseBtn, $GUI_DISABLE);没有开始,不能暂停
GUISetState(@SW_SHOW)
Global $cycle = 1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE ;关闭窗口
ExitLoop
Exit
Case $StartBtn ;开始
StartEvt()
Case $PauseBtn ;停止
AdlibUnRegister("_pk")
PauseEvt()
EndSwitch
WEnd
;---------------------------------------/
Func StartEvt()
GUICtrlSetState($StartBtn, $GUI_DISABLE);不能重复开始
GUICtrlSetState($PauseBtn, $GUI_ENABLE) ;激活暂停
Local $pk = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $PauseBtn ;停止
PauseEvt()
EndSwitch
;这里放了一些代码(延时执行)……用自动函数替代
;------------------------
If Not $pk Then
AdlibRegister("_pk", 10000)
$pk = 1
EndIf
;-------------------------
If $cycle Then
ContinueLoop
ElseIf Not $cycle Then
ExitLoop
EndIf
WEnd
EndFunc ;==>StartEvt
;---------------------------------------/
Func PauseEvt()
GUICtrlSetState($StartBtn, $GUI_ENABLE) ;激活开始
GUICtrlSetState($PauseBtn, $GUI_DISABLE);关闭暂停
;希望通过改变$cycle的量来控制StartEvt中的死循环停止
If $cycle = 1 Then
$cycle = 0
EndIf
EndFunc ;==>PauseEvt
;---------------------------------------/
Func _pk()
AdlibUnRegister("_pk")
;这里放了一些代码
ConsoleWrite(@LF & @KBLayout & @CR)
GUICtrlSetState($StartBtn, $GUI_ENABLE) ;激活开始
GUICtrlSetState($PauseBtn, $GUI_DISABLE);关闭暂停
$cycle = 0
MsgBox(0,0,"PK结束",2)
EndFunc ;==>_pk
;---------------------------------------/
|