随笔 - 52,  文章 - 0,  评论 - 7,  阅读 - 10011

为什么

这其实是一种两阶段XX的设计模式,比如两阶段终止:调用终止方法时并不立即终止,而是设置终止信号,由别人自身决定终止的操作。

同样,实现Show()方法算是一种两阶段启动:外部调用Show()方法时,由自身决定show前做什么,show后又做什么,以及如何show。

例子

这是一个Show()方法:

static Show(config, *) {
; singleton
for w in WinGetList('ahk_pid ' ProcessExist())
if (g := GuiFromHwnd(w)) && g.base = this.Prototype
return g.Show()
; =========Show()前
ins := PlanEGui(config.theme)
ins.Show('Minimize')
; =========Show()后
WinSetTransparent(0, 'ahk_id' ins.Hwnd)
ins.Restore()
ins.GetClientPos(, , , &ch)
ins.Move(, A_ScreenHeight / 4, , 0)
WinSetTransparent(255, 'ahk_id' ins.Hwnd)
loop ch {
ins.Move(, , , A_Index)
}
ins.AddText('xm+5 h800 w400 vHistory c' ins.currTheme.edit_Fc,)
ins['History'].SetFont('s12')
ControlFocus ins['SendBox'].Hwnd, "A"
}

在这个Show()方法中,

  • show前:判断是否已存在当前脚本的实例,如果有返回此实例。
  • show时:设置必须的gui选项并组合传入的option。
  • show后:
    • 实现更好的启动画面:将窗口实例透明度设为0,然后恢复窗口并将宽设为0,再逐渐恢复宽度,使窗口缓慢出现。
    • 为实例进行额外的操作。
    • 聚焦期望的控件。
posted on   落寞的雪  阅读(105)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示