找回密码
 加入
搜索
查看: 5136|回复: 12

[GUI管理] 窗体加入一个倒计时关闭要怎么写呢

 火.. [复制链接]
发表于 2011-1-17 18:56:13 | 显示全部楼层 |阅读模式
本帖最后由 qzhid 于 2011-3-3 00:46 编辑

一个GUI窗体程序加入一个倒计时关闭要怎么写呢


谢谢大家的解答,已想到方法了,怎么弄到已解决区呢.
发表于 2011-1-17 20:06:29 | 显示全部楼层
#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 
发表于 2011-1-17 20:23:19 | 显示全部楼层
本帖最后由 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
发表于 2011-1-18 09:17:08 | 显示全部楼层
2楼5秒,3楼10秒的窗体倒计时.原理一样.
发表于 2011-2-6 01:31:34 | 显示全部楼层
哈,又学到了。。。
发表于 2011-2-6 01:32:20 | 显示全部楼层
也就是IF语句组成的哈。。。
发表于 2011-2-6 02:50:21 | 显示全部楼层
消息模式:
$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

后一种是最高效的.
发表于 2011-2-6 03:38:18 | 显示全部楼层
凑下热闹
#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
发表于 2011-2-6 03:57:11 | 显示全部楼层
用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
发表于 2011-2-7 01:42:16 | 显示全部楼层
使用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
 楼主| 发表于 2011-3-3 00:47:40 | 显示全部楼层
谢谢大家,问题已解决
发表于 2011-3-3 11:04:52 | 显示全部楼层
学习中,都 是高手
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-16 09:50 , Processed in 0.087004 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表