建议用事件模式+adlib吧,这个嵌套了GUIGetMsg(),不容易看清程序结构
没注意到4楼循环锁死了,4楼建议真是不行的
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 487, 98)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$Progress1 = GUICtrlCreateProgress(8, 72, 465, 17)
GUICtrlSetData(-1, 0)
$Button1 = GUICtrlCreateButton("开始", 48, 16, 105, 33)
GUICtrlSetOnEvent(-1, "start")
$Button2 = GUICtrlCreateButton("中止", 168, 16, 105, 33)
GUICtrlSetState(-1, $gui_disable)
GUICtrlSetOnEvent(-1, "stop")
$Button3 = GUICtrlCreateButton("退出", 288, 16, 97, 33)
GUICtrlSetOnEvent(-1, "quit")
Global $starti = 0, $stopi = 30
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func quit()
Exit
EndFunc ;==>quit
Func stop()
AdlibUnRegister("Progress")
setstate()
MsgBox(0, "操作被中止", "操作被中止, 最后的 $i 是:" & $starti)
EndFunc ;==>stop
Func start()
GUICtrlSetState($Button1, $gui_disable)
GUICtrlSetState($Button2, $gui_enable)
GUICtrlSetState($Button3, $gui_disable)
GUICtrlSetData($Progress1, 0)
$starti = 0
AdlibRegister("Progress")
EndFunc ;==>start
Func setstate()
GUICtrlSetState($Button1, $gui_enable)
GUICtrlSetState($Button2, $gui_disable)
GUICtrlSetState($Button3, $gui_enable)
EndFunc ;==>setstate
Func Progress()
$starti += 1
GUICtrlSetData($Progress1, $starti * 100 / $stopi)
If $starti = $stopi Then
AdlibUnRegister("Progress")
setstate()
EndIf
EndFunc ;==>Progress
|