本帖最后由 zghwelcome 于 2019-12-29 20:05 编辑
#include <WindowsConstants.au3>
Global $bBoolean = True
Global $Checkbox[4]
Global $hGUI = GUICreate('', 300, 400)
$Checkbox[0] = GUICtrlCreateCheckbox('循环1', 60, 50, 97, 17)
GUICtrlSetFont(-1, 12, 400, 0, '微软雅黑')
$Checkbox[1] = GUICtrlCreateCheckbox('循环2', 180, 50, 97, 17)
GUICtrlSetFont(-1, 12, 400, 0, '微软雅黑')
$Checkbox[2] = GUICtrlCreateCheckbox('循环3', 60, 100, 97, 17)
GUICtrlSetFont(-1, 12, 400, 0, '微软雅黑')
$Checkbox[3] = GUICtrlCreateCheckbox('循环4', 180, 100, 97, 17)
GUICtrlSetFont(-1, 12, 400, 0, '微软雅黑')
$Label1 = GUICtrlCreateLabel('', 50, 200, 200, 20, 0x01 + 0x0200)
GUICtrlSetFont(-1, 12, 400, 0, '微软雅黑')
$Label2 = GUICtrlCreateLabel('准备就绪', 50, 250, 200, 20, 0x01 + 0x0200)
GUICtrlSetFont(-1, 14, 400, 0, '微软雅黑')
$Button1 = GUICtrlCreateButton('开始', 50, 300, 80, 30)
$Button2 = GUICtrlCreateButton('结束', 170, 300, 80, 30)
GUISetState()
GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
$bBoolean = True
For $i = 0 To UBound($Checkbox) - 1
If Not $bBoolean Then ExitLoop
If GUICtrlRead($Checkbox[$i]) = 1 Then
Local $vLoopNum = Random(5,10,1)
GUICtrlSetData($Label1, '正在执行 循环' & $i + 1)
_Loop($i + 1 ,$vLoopNum)
EndIf
Next
EndSwitch
WEnd
Func _Loop($vLoopIndex , $vLoopNum)
For $j = 1 To $vLoopNum
GUICtrlSetData($Label2, '循环' & $vLoopIndex & ' ' & $j & '/' & $vLoopNum)
For $t = 1 To 2
Sleep(250)
If Not $bBoolean Then Return GUICtrlSetData($Label1, '手动结束循环')
Next
Next
EndFunc ;==>_Loop
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
$iCode = BitShift($iwParam, 16)
Switch $ilParam
Case GUICtrlGetHandle($Button2)
$bBoolean = False
EndSwitch
Return
EndFunc ;==>WM_COMMAND
Func On_WM_SYSCOMMAND($hWnd, $nMsg, $wParam, $lParam)
Local Const $SC_CLOSE = 0xF060
Switch BitAND($wParam, 0xFFF0)
Case $SC_CLOSE
GUIDelete()
Exit
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc ;==>On_WM_SYSCOMMAND
最好的方式应该是hook检测窗口的消息
|