回复 1# dearmb #include <GUIConstantsEx.au3>
Local $iCount = 0
$Form2 = GUICreate("MarinaClick", 260, 430, 270, 150)
$Button1 = GUICtrlCreateButton("开始", 20, 20, 225, 190)
$Button2 = GUICtrlCreateButton("停止", 20, 220, 225, 190)
Local $aAccelKeys[2][2] = [["^b", $Button1],["^s", $Button2]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$iCount = 0
While 1
$iCount += 1
;ConsoleWrite('当前循环次数: ' & $iCount & @CRLF)
If GUIGetMsg() = $Button2 Then ExitLoop
WEnd
Case $Button2
ExitLoop
EndSwitch
WEnd
Terminate()
Func Terminate()
If $iCount Then MsgBox(0, '', '已经进行了' & $iCount & '次循环')
Exit
EndFunc ;==>Terminate
缺点是: 欲终止循环时,无论是按热键还是点击停止按钮,一般都要连按(点击)两次才会有响应! |