在AutoHotkey v2 中设计GUI窗口,窗口中有个文本框,可以定时刷新内容。 时间周期可以通过窗口中的 下拉框来设定。
/************************************************************************
* @description
* @file 控件自动更新.ahk
* @author sunwind1576157
* @date 2024/07/02
* @version 0.0.1
***********************************************************************/
myGui := Gui()
myGui.Add("Text",, "请选择更新周期:")
myCmb:=myGui.AddComboBox("vPeriodChoice ", ["1","5","10"])
myEdt:=myGui.AddEdit("vTimer")
myGui.Show()
myCmb.OnEvent("Change", setConunter)
setConunter(*)
{
counter := SecondCounter(myCmb.Text)
counter.Start
myEdt.Value:="第0次运行," FormatTime("T12", "Time")
}
class SecondCounter {
__New(秒数:=1) {
this.interval := 1000*秒数
this.count := 0
; Tick() 有一个隐式参数 "this", 其引用一个对象
; 所以, 我们需要创建一个封装了 "this " 和调用方法的函数:
this.timer := ObjBindMethod(this, "Tick")
}
Start() {
SetTimer this.timer, this.interval
ToolTip "Counter started"
}
Stop() {
; 要关闭计时器, 我们必须传递和之前一样的对象:
SetTimer this.timer, 0
ToolTip "Counter stopped at " this.count
}
Tick() {
++this.count
myEdt.Value:="第" this.count "次运行," FormatTime("T12", "Time")
}
}