[已解决]谁能分享下AU3自带的暂停/退出源码?感谢大家热心回复!
本帖最后由 fybhwsx 于 2023-5-2 19:48 编辑想在暂停期间执行一些操作,比如:增加计时退出或解除暂停……
Local $g_bPaused = False
HotKeySet('{PAUSE}', 'TogglePause') ;按pause/break 暂停/恢复 快捷键
Func TogglePause()
$g_bPaused = Not $g_bPaused
Local $js = 0
While $g_bPaused
TraySetState(4);闪烁托盘图标
$js += 1
Sleep(250)
If $js > 40 Then
TraySetState(8);停止闪烁托盘图标
$g_bPaused = False
EndIf
WEnd
EndFunc
本帖最后由 anythinging 于 2023-5-2 11:15 编辑
中途使用
while 1
条件......exitloop
wend
$hTimer = TimerInit()
while 1
If TimerDiff($hTimer) >= 5000 Then exitloop;超过5秒退出循环
wend https://www.autoitx.com/thread-55168-1-1.html
可以看看这个 控制循环中的状态 为什么要用自带的,自己模拟一个不好吗。自己写逻辑就可以添加操作了 托盘菜单中的暂停退出是调试程序用的。是解释器带的功能,无法利用。如果想使用,可以自己写代码重现功能。 本帖最后由 zghwelcome 于 2023-5-2 19:07 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 360, 179)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
$Button_start = GUICtrlCreateButton("运行", 24, 64, 73, 41)
$Button_stop = GUICtrlCreateButton("停止", 102, 64, 73, 41)
$Button_pause = GUICtrlCreateButton("暂停", 182, 64, 73, 41)
$Button_Exit = GUICtrlCreateButton("退出", 260, 64, 73, 41)
GUICtrlSetState($Button_stop, 128)
GUICtrlSetState($Button_pause, 128)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $_g_stop = False, $_g_pause = False
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button_start
GUICtrlSetState($Button_start, 128)
GUICtrlSetState($Button_stop, 64)
GUICtrlSetState($Button_pause, 64)
_Run()
GUICtrlSetState($Button_start, 64)
GUICtrlSetState($Button_stop, 128)
GUICtrlSetState($Button_pause, 128)
EndSwitch
WEnd
Func _Run()
$_g_stop = False
_GUICtrlStatusBar_SetText($StatusBar1, ' 运行...')
While $_g_stop = False
Sleep(100)
_Pause()
WEnd
_GUICtrlStatusBar_SetText($StatusBar1, ' 已停止.')
EndFunc ;==>_Run
Func _Pause()
While $_g_pause And $_g_stop = False
Sleep(10)
WEnd
EndFunc ;==>_Pause
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $iCtrlID = BitAND($iwParam, 0x0000FFFF)
Local $nNotifyCode = BitShift($iwParam, 16)
Switch $iCtrlID
Case $Button_Exit
Exit
Case $Button_stop
$_g_stop = True
Case $Button_pause
$_g_pause = Not $_g_pause
If $_g_pause Then
_GUICtrlStatusBar_SetText($StatusBar1, ' 已暂停.')
GUICtrlSetData($iCtrlID, '恢复')
Else
_GUICtrlStatusBar_SetText($StatusBar1, ' 运行...')
GUICtrlSetData($iCtrlID, '暂停')
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
页:
[1]