V1代码:

#Persistent

hook := New ShellHook("ShellHookFunc")
Return

F1::DllCall("FlashWindow", "Ptr", WinActive("A"), "int", True)  ; 让当前窗口激活闪烁

ShellHookFunc(wParam, lParam, msg, hwnd) {
    if (wParam == 32774) {
        WinGetClass, 类名, ahk_id %lParam%
        ToolTip % 类名 " 闪烁了"
    }
}

Class ShellHook {
    Static RefCount := 0, Message := DllCall("RegisterWindowMessage", "Str", "ShellHook")

    __New(function) {
        if (!ShellHook.RefCount++)
            DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
        OnMessage(ShellHook.Message, this.function := function)
    }

    __Delete() {
        if (!--ShellHook.RefCount)
            DllCall("DeregisterShellHookWindow", "Ptr", A_ScriptHwnd)
        OnMessage(ShellHook.Message, this.function, 0)
    }
}

 

V2代码:

#Requires AutoHotkey v2.0
Persistent
; 监控窗口闪烁【F1那行不需要的,只要改下回调函数就行了】
; 不需要轮询,注册钩子后有窗口闪烁就会自动触发回调,在回调里加个判断然后随你怎么整

F1::DllCall("FlashWindow", "ptr", WinExist("A"), "int", true)  ; 让当前窗口激活闪烁

hook := ShellHook((wParam, lParam, *) => wParam == 32774 && ToolTip(WinGetClass(lParam) " 闪烁了"))

; hook := ShellHook((wParam, lParam, *) => wParam == 32774 && WinActivate("fjjfif"))

class ShellHook {
  static Message := DllCall("RegisterWindowMessage", "str", "ShellHook")

  static RefCount := 0

    __New(function) {
        !ShellHook.RefCount++ ? DllCall("RegisterShellHookWindow", "ptr", A_ScriptHwnd) : ""
        OnMessage(ShellHook.Message, this.function := function)
    }

    __Delete() {
        !--ShellHook.RefCount ? DllCall("DeregisterShellHookWindow", "ptr", A_ScriptHwnd) : ""
        OnMessage(ShellHook.Message, this.function, 0)
    }
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。