本帖最后由 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
|