窗体加入一个倒计时关闭要怎么写呢
本帖最后由 qzhid 于 2011-3-3 00:46 编辑一个GUI窗体程序加入一个倒计时关闭要怎么写呢
谢谢大家的解答,已想到方法了,怎么弄到已解决区呢. #include <GuiConstants.au3>
GUICreate ("",150,60)
$Label=GUICtrlCreateLabel("5秒后自动退出!",15,30)
$Label_1=GUICtrlCreateLabel("5 ",125,30)
;$N=
GUISetState ()
For $i=5 To 1 Step -1
GUICtrlSetData($Label_1,$i)
Sleep(1000)
If $i=1 Then Exit
Next
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend 本帖最后由 lizhou 于 2011-1-17 20:24 编辑
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
$mu=GUICreate("无聊", "300", "50")
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
$sj = GUICtrlCreateLabel("", 215, 0, 200, 21)
GUISetState(@SW_SHOW)
For $i = 10 To 0 Step -1
GUICtrlSetData($sj, $i & "秒后自动关闭")
Sleep(1000)
Next
Func close()
exit
EndFunc 2楼5秒,3楼10秒的窗体倒计时.原理一样. 哈,又学到了。。。 也就是IF语句组成的哈。。。 消息模式:
$Title = GUICreate("", 300, 150)
GUISetState()
Local $i = 200
While $i And GUIGetMsg() + 3
$i -= 1
WinSetTitle($Title, "", "窗口将在 " & Int($i / 10) & " 秒后自动退出")
Sleep(100)
WEnd
事件模式:
Opt("GUIOnEventMode", 1)
$Title = GUICreate("", 300, 150)
GUISetOnEvent(-3, "GuiEvent")
GUISetState()
Local $i = 200
While $i
$i -= 1
WinSetTitle($Title, "", "窗口将在 " & Int($i / 10) & " 秒后自动退出")
Sleep(100)
WEnd
Func GuiEvent()
Exit
EndFunc
后一种是最高效的. 凑下热闹
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
$Form1 = GUICreate("倒计时", 340, 194, 192, 124)
$Button1 = GUICtrlCreateButton("点击暂停(10)", 72, 40, 185, 97)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
$Timer = _Timer_SetTimer($Form1, 1000, "update")
GUISetState(@SW_SHOW)
Global $Check = 10
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If GUICtrlRead($Button1) = "暂停中" Then
$Timer = _Timer_SetTimer($Form1, 1000, "update")
Else
_Timer_KillTimer($Form1, $Timer)
GUICtrlSetData($Button1,"暂停中")
EndIf
EndSwitch
Sleep(100)
WEnd
Func update($hWnd, $Msg, $iIDTimer, $dwTime)
$Check -= 1
GUICtrlSetData($Button1, "点击暂停(" & $Check & ")")
If $Check = 0 Then
_Timer_KillTimer($Form1, $Timer)
Exit MsgBox(64, "提示", "倒计时结束")
EndIf
EndFunc ;==>update
用AdlibRegister或AdlibEnable其实也可以的
Opt("GUIOnEventMode", 1)
Local $Time=5,$Begin = TimerInit()
AdlibRegister( "Quit" ,$Time*1000)
GUICreate ("",150,60)
GUISetOnEvent(-3, "Quit")
$TD=GUICtrlCreateLabel("再 " & $Time-Int(TimerDiff($begin) / 1000)& " 秒后自动退出",15,30)
GUISetState ()
While 1
GUICtrlSetData($TD, "再 " & $Time-Int(TimerDiff($begin) / 1000)& " 秒后自动退出")
Sleep(100)
WEnd
Func Quit()
Exit
EndFunc
使用AdlibRegister的例子,倒计时10秒退出。
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Local $i = 10
AdlibRegister('_ADlib',1000)
$Form1 = GUICreate("倒计时例子", 327, 277, 343, 231)
$Label1 = GUICtrlCreateLabel("10秒后自动退出程序", 64, 56, 184, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _ADlib()
GUICtrlSetData($Label1,$i-1&'秒后自动退出程序')
$i = $i -1
If $i = 0 Then Exit
EndFunc 谢谢大家,问题已解决 学习中,都 是高手
页:
[1]