|
楼主 |
发表于 2022-2-10 10:32:21
|
显示全部楼层
感谢A版指点,将While与多个定时器代码最终整理如下,有需要的朋友可以拿去参考:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <Timers.au3>
Global $i = 0,$ii = 0,$ix = 0
Global $text1,$text2,$text3
Example()
Func Example()
$hGUI = GUICreate("下拉菜单导致While中断", 300, 200)
Local $idViewMenu = GUICtrlCreateMenu("查看", -1, 1)
Local $idViewStatusItem = GUICtrlCreateMenuItem("状态栏", $idViewMenu)
GUICtrlCreateLabel('While',20,50)
$text1 = GUICtrlCreateLabel('0',120,50,50,10)
GUICtrlCreateLabel('计时器1',20,70)
$text2 = GUICtrlCreateLabel('0',120,70,50,10)
GUICtrlCreateLabel('计时器2',20,90)
$text3 = GUICtrlCreateLabel('0',120,90,50,10)
GUISetState(@SW_SHOW)
$start1 = GUICtrlCreateButton('启动计时器1',20,120,100,20)
$kill1 = GUICtrlCreateButton('停止计时器1',120,120,100,20)
$start2 = GUICtrlCreateButton('启动计时器2',20,140,100,20)
$kill2 = GUICtrlCreateButton('停止计时器2',120,140,100,20)
$iIDtimer1 = _Timer_SetTimer($hGUI, 500, "_Time1") ; 创建计时器1
$iIDtimer2 = _Timer_SetTimer($hGUI, 500, "_Time2") ; 创建计时器2
;AdlibRegister('time',1000)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $start1
$ii = 0
_Timer_KillTimer($hGUI, $iIDtimer1)
$iIDtimer1 = _Timer_SetTimer($hGUI, 1000, "_Time1") ; 创建计时器
Case $kill1
_Timer_KillTimer($hGUI, $iIDtimer1)
Case $start2
$ix = 0
_Timer_KillTimer($hGUI, $iIDtimer2)
$iIDtimer2 = _Timer_SetTimer($hGUI, 1000, "_Time2") ; 创建计时器
Case $kill2
_Timer_KillTimer($hGUI, $iIDtimer2)
EndSwitch
$i += 1
GUICtrlSetData($text1,$i)
Sleep(50)
WEnd
EndFunc ;==>Example
Func time()
$ii += 0.5
GUICtrlSetData($text2,$ii)
EndFunc
Func _Time1($hWnd, $iMsg, $iIDTimer, $iTime)
#forceref $hWnd, $iMsg, $iIDTimer, $iTime
$ii += 0.5
GUICtrlSetData($text2,$ii)
EndFunc
Func _Time2($hWnd, $iMsg, $iIDTimer, $iTime)
#forceref $hWnd, $iMsg, $iIDTimer, $iTime
$ix += 0.2
GUICtrlSetData($text3,$ix)
EndFunc
|
|