本文主要演示用Class来的成员属性来记录窗口的数据、用类的成员函数实现激活动作
测试方法,先启动一个记事本。
Ctrl+Alt+a激活时会提示你需要先绑定窗口
Ctrl+Alt+b 绑定记事本窗口
绑定后,就可以用Ctrl+Alt+a来激活被绑定的记事本窗口了。
#SingleInstance force
;Declare Class
Class Window{
Class Tmp{
A:=1
Static B:=1
}
Get()
{
WingetTitle TitleVar, A ; Get title from Active window.
This.Title:=TitleVar ; Set TitleVar to This.Title
WinGet IDVar,ID,A ; Get ID from Active window.
This.ID:=IDVar ; Set IDVar to This.ID
}
Activate() ;Activates window with Title - This.Title
{
IfWinExist, % "ahk_id "This.ID
WinActivate % "ahk_id " This.ID
else
MsgBox % "There is no Window with ID: "This.ID
}
AnnounceWinProps() ;Create message box with title and ID
{
MsgBox % "Title is: " This.Title "`n ID is: " This.ID
}
}
;Create Instance
SomeWin:= New Window
return
;绑定窗口
^!b:: ;Hotkey to run Instance Method
WinActivate ahk_class Notepad
SomeWin.get()
SomeWin.AnnounceWinProps()
Return
;激活窗口
^!a::
If SomeWin.ID
SomeWin.Activate()
else
MsgBox Instance SomeWindow has no ID setted, pleas run SomeWin.get() first!
return
;窗口类中的属性
^!d::
MsgBox % "SomeWin.Tmp.A = "SomeWin.Tmp.A "`nSomeWin.Tmp.B = "SomeWin.Tmp.B
return
;————————————————
;版权声明:本文为CSDN博主「liuyukuan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
;原文链接:https://blog.csdn.net/liuyukuan/article/details/128660697
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
感觉这个类容易看懂!Mark一下