放上星驰周大哥给我的解决方案,供大家参考
#include
#include
#include
#include
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 559, 316, 192, 124)
$Button1 = GUICtrlCreateButton("开始循环", 168, 122, 177, 45, 0)
$Button2 = GUICtrlCreateCheckbox("退出循环", 168, 182, 177, 65, 0)
GUICtrlSetState($Button2, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("while的退出问题!", 136, 56, 256, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_UNCHECKED)
;循环的间隔秒数,显示的次数
Dim $i = 3, $j = 0
While 1
If GUICtrlRead($Button2) = $GUI_CHECKED Then
GUICtrlSetState($Button2, $GUI_DISABLE)
TrayTip("", "", 1)
ExitLoop
EndIf
;------------------以下是自定义代码部分-------------------
Sleep($i * 1000)
$j = $j + 1
TrayTip("脚本正在循环中", "目的是第" & $j & "次", 10, 1)
;------------------以上是自定义代码部分-------------------
WEnd
Case $Button2
MsgBox(0, "你按了退出键", "但是没有退出效果!哈哈", 2)
EndSwitch
WEnd
MsgBox(0, "", "退出成功了")
|