注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

翱翔的板儿砖

——燃烧吧,小宇宙!

 
 
 

日志

 
 

[AU3] AutoIt 编写计时器  

2008-07-24 11:24:42|  分类: 编程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

小众昨天发表了TimerQ - 简单的倒计时,看着很简单,于是用 AutoIt 参照 TimerQ 来编写了一个。还有些小问题,比如自定义时间未到时不能重新设置、自定义事件后文本框内容不清空等。逻辑上没问题,可是技术手段还不行,已经在论坛上提问……

先附上代码:

#include <ButtonConstants.au3>
#include
<EditConstants.au3>
#include
<GUIConstantsEx.au3>
#include
<StaticConstants.au3>
#include
<WindowsConstants.au3>

Opt("GUIOnEventMode",
1
)
Opt("TrayMenuMode",
1
)
Opt("TrayOnEventMode",
1
)
$formOption = GUICreate("自定义时间", 351, 91, -1, -1
)
GUISetOnEvent($GUI_EVENT_CLOSE,
"formOptionClose"
)
GUISetOnEvent($GUI_EVENT_MINIMIZE,
"formOptionClose"
)
$lblPrompt = GUICtrlCreateLabel("提示信息", 8, 8, 52, 17
)
$iptPrompt = GUICtrlCreateInput("", 8, 25, 273, 21
)
$lblTime = GUICtrlCreateLabel("时间", 288, 8, 28, 17
)
$iptTime = GUICtrlCreateInput("1", 288, 25, 33, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER
))
$lblUnit = GUICtrlCreateLabel("分", 328, 27, 16, 17
)
$btnOk = GUICtrlCreateButton("确定(&O)", 264, 56, 75, 25, 0
)
GUICtrlSetOnEvent(-1,
"btnOkClick"
)
TraySetClick("9"
)
$mi3 = TrayCreateItem("3 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi3Click"
)
$mi5 = TrayCreateItem("5 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi5Click"
)
$mi10 = TrayCreateItem("10 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi10Click"
)
$mi15 = TrayCreateItem("15 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi15Click"
)
$mi20 = TrayCreateItem("20 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi20Click"
)
$mi30 = TrayCreateItem("30 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi30Click"
)
$miSprt1 = TrayCreateItem(""
)
$miCustom = TrayCreateItem("自定义时间"
)
TrayItemSetOnEvent(-1,
"miCustomClick"
)
$miSprt2 = TrayCreateItem(""
)
$miExit = TrayCreateItem("退出"
)
TrayItemSetOnEvent(-1,
"miExitClick"
)
GUISetState(@SW_HIDE
)
Local
$SleepTime
Local
$StartTimeStamp
Local
$Prompt

While
1
    Sleep(100
)
    If $SleepTime > 0
Then
        If TimerDiff($StartTimeStamp) > $SleepTime * 60000
Then
            $SleepTime =
0
            $Prompt =
""
            MsgBox(48,"提示",$Prompt
)
       
EndIf
   
EndIf
WEnd

Func
btnOkClick
()
    $PromptText = GUICtrlRead($iptPrompt
)
    $Time = GUICtrlRead($iptTime
)
    GUICtrlSetData($iptPrompt, ""
)
    GUICtrlSetData($iptTime, "0"
)
    GUISetState(@SW_HIDE, $formOption
)
    SetTimer($PromptText, $Time
)
EndFunc
Func
formOptionClose
()
    GUISetState(@SW_HIDE, $formOption
)
EndFunc
Func
mi10Click
()
    SetTimer(CreatePromptText(10), 10
)
EndFunc
Func
mi15Click
()
    SetTimer(CreatePromptText(15), 15
)
EndFunc
Func
mi20Click
()
    SetTimer(CreatePromptText(20), 20
)
EndFunc
Func
mi30Click
()
    SetTimer(CreatePromptText(30), 30
)
EndFunc
Func
mi3Click
()
    SetTimer(CreatePromptText(3), 3
)
EndFunc
Func
mi5Click
()
    SetTimer(CreatePromptText(5), 5
)
EndFunc
Func
miCustomClick
()
    GUISetState(@SW_SHOW, $formOption
)
EndFunc
Func
miExitClick
()
   
Exit
EndFunc

Func
SetTimer($PrptTxt, $Min
)
    $StartTimeStamp = TimerInit
()
    $SleepTime =
$Min
    $Prompt =
$PrptTxt
   
#cs
    Sleep($Min * 60000)
    if $PrptTxt = "" Then
        $PrptTxt = "您设置的时间到!"
    EndIf
    TrayTip("", $PrptTxt, 2000)
    MsgBox(48, "提示", $PrptTxt)
    #ce
EndFunc
Func
CreatePromptText ($Min
)
    Return "您设置的" & $Min & "分钟时间到!"
EndFunc


之前的代码,用做对比:

#include <ButtonConstants.au3>
#include
<EditConstants.au3>
#include
<GUIConstantsEx.au3>
#include
<StaticConstants.au3>
#include
<WindowsConstants.au3>

Opt("GUIOnEventMode",
1
)
Opt("TrayMenuMode",
1
)
Opt("TrayOnEventMode",
1
)
$formOption = GUICreate("自定义时间", 351, 91, -1, -1
)
GUISetOnEvent($GUI_EVENT_CLOSE,
"formOptionClose"
)
GUISetOnEvent($GUI_EVENT_MINIMIZE,
"formOptionClose"
)
$lblPrompt = GUICtrlCreateLabel("提示信息", 8, 8, 52, 17
)
$iptPrompt = GUICtrlCreateInput("", 8, 25, 273, 21
)
$lblTime = GUICtrlCreateLabel("时间", 288, 8, 28, 17
)
$iptTime = GUICtrlCreateInput("1", 288, 25, 33, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER
))
$lblUnit = GUICtrlCreateLabel("分", 328, 27, 16, 17
)
$btnOk = GUICtrlCreateButton("确定(&O)", 264, 56, 75, 25, 0
)
GUICtrlSetOnEvent(-1,
"btnOkClick"
)
TraySetClick("9"
)
$mi3 = TrayCreateItem("3 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi3Click"
)
$mi5 = TrayCreateItem("5 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi5Click"
)
$mi10 = TrayCreateItem("10 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi10Click"
)
$mi15 = TrayCreateItem("15 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi15Click"
)
$mi20 = TrayCreateItem("20 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi20Click"
)
$mi30 = TrayCreateItem("30 分钟提醒"
)
TrayItemSetOnEvent(-1,
"mi30Click"
)
$miSprt1 = TrayCreateItem(""
)
$miCustom = TrayCreateItem("自定义时间"
)
TrayItemSetOnEvent(-1,
"miCustomClick"
)
$miSprt2 = TrayCreateItem(""
)
$miExit = TrayCreateItem("退出"
)
TrayItemSetOnEvent(-1,
"miExitClick"
)
GUISetState(@SW_HIDE
)

While
1
    Sleep(100
)
WEnd

Func
btnOkClick
()
    $PromptText = GUICtrlRead($iptPrompt
)
    $Time = GUICtrlRead($iptTime
)
    GUICtrlSetData($iptPrompt, ""
)
    GUICtrlSetData($iptTime, "0"
)
    GUISetState(@SW_HIDE, $formOption
)
    SetTimer($PromptText, $Time
)
EndFunc
Func
formOptionClose
()
    GUISetState(@SW_HIDE, $formOption
)
EndFunc
Func
mi10Click
()
    SetTimer(CreatePromptText(10), 10
)
EndFunc
Func
mi15Click
()
    SetTimer(CreatePromptText(15), 15
)
EndFunc
Func
mi20Click
()
    SetTimer(CreatePromptText(20), 20
)
EndFunc
Func
mi30Click
()
    SetTimer(CreatePromptText(30), 30
)
EndFunc
Func
mi3Click
()
    SetTimer(CreatePromptText(3), 3
)
EndFunc
Func
mi5Click
()
    SetTimer(CreatePromptText(5), 5
)
EndFunc
Func
miCustomClick
()
    GUISetState(@SW_SHOW, $formOption
)
EndFunc
Func
miExitClick
()
   
Exit
EndFunc

Func
SetTimer($PrptTxt, $Min
)
    Sleep($Min * 60000
)
    if $PrptTxt = ""
Then
        $PrptTxt =
"您设置的时间到!"
   
EndIf
    TrayTip("", $PrptTxt, 2000
)
    MsgBox(48, "提示", $PrptTxt
)
EndFunc
Func
CreatePromptText ($Min
)
    Return "您设置的" & $Min & "分钟时间到!"
EndFunc

  评论这张
 
阅读(1952)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017