[AHK]面向对象--窗口类

61 篇文章 6 订阅
6 篇文章 0 订阅

测试方法,先启动一个记事本。

Ctrl+Alt+a激活时会提示你需要先绑定窗口

Ctrl+Alt+b 绑定记事本窗口

绑定后,就可以用Ctrl+Alt+a来激活被绑定的记事本窗口了。

本文主要演示用Class来的成员属性来记录窗口的数据、用类的成员函数实现激活动作

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值