窗口/控件高亮外框线

/*
    提取自accviewer
*/

Highlightline := new HighlightOutline()

#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:
    CoordMode,Mouse,Screen
    MouseGetPos, x, y, id, control
    WinGetTitle, title, ahk_id %id%
    WinGetClass, class, ahk_id %id%
    WinGetPos , Xpos, Ypos, Width, Height, ahk_id%id%
    if (Control<>""){
        ControlGetPos , X, Y, Width, Height, %Control%, ahk_id%id%
        Xpos:=Xpos+x,Ypos:=Ypos+y
    }
    ToolTip, ahk_id: %id%`nahk_class: %class%`nWinTitle: %title%`nControl: %control%
    Highlightline.show(Xpos, Ypos, Xpos+Width, Ypos+Height)
    Highlightline.setabove(id)
return

GetAccLocation(AccObj, Child=0, byref x="", byref y="", byref w="", byref h="") {
    AccObj.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), Child)
    return "x" (x:=NumGet(x,0,"int")) "  "
    .    "y" (y:=NumGet(y,0,"int")) "  "
    .    "w" (w:=NumGet(w,0,"int")) "  "
    .    "h" (h:=NumGet(h,0,"int"))
}

class HighlightOutline {
    __New(color="red") {
        static WS_EX_TRANSPARENT := 0x20, WS_EX_LAYERED := 0x00080000

        preDefaultGui := A_DefaultGui

        this.hwnds := {}
        Loop, 4 {
            Gui, New, -Caption +ToolWindow HWNDhwnd -DPIScale +E%WS_EX_TRANSPARENT% +E%WS_EX_LAYERED%
            Gui, Color, %color%
            this[A_Index] := hwnd
            DllCall("SetLayeredWindowAttributes", "ptr", hwnd, uint, 0, "uchar", 255, "int", 2)
        }
        this.isVisible := false
        this.color := color
        this.top := this[1]
        this.right := this[2]
        this.bottom := this[3]
        this.left := this[4]
        Gui, %preDefaultGui%: Default
    }

    MoveTogether(arrHwnd, arrPos) {
        hDWP := DllCall("BeginDeferWindowPos", "int", arrHwnd.Length(), "ptr")
        for i, v in arrPos {
            DllCall("DeferWindowPos", "ptr", hDWP, "ptr", arrHwnd[i], "ptr", 0
                , "int", v[1], "int", v[2], "int", v[3], "int", v[4]
                , "uint", 0x54) ; SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER
        }
        DllCall("EndDeferWindowPos", "ptr", hDWP)
    }
    Show(x1, y1, x2, y2) {
        b := g_isWindowDpiAware ? Round(2*(A_ScreenDPI/96)) : 2

        arrHwnd := [this.1, this.2, this.3, this.4]
        arrPos  := [ [x1-b, y1-b, x2-x1+b*2, b]
                   , [x2,   y1,   b,         y2-y1]
                   , [x1-b, y2,   x2-x1+b*2, b]
                   , [x1-b, y1,   b,         y2-y1] ]
        this.MoveTogether(arrHwnd, arrPos)

        ; this.GuiShow("top",    x1-b, y1-b, x2-x1+b*2, b)
        ; this.GuiShow("right",  x2,   y1,   b,         y2-y1)
        ; this.GuiShow("bottom", x1-b, y2,   x2-x1+b*2, b)
        ; this.GuiShow("left",   x1-b, y1,   b,         y2-y1)

        this.isVisible := true
    }
    GuiShow(name, x, y, w, h) {
        Gui, % this[name] ":Show", % "NA x" x " y" y " w" w " h" h
    }
    Hide() {
        Loop, 4
            Gui, % this[A_Index] ": Hide"
        this.isVisible := false
    }
    SetAbove(hwnd) {
        ABOVE := DllCall("GetWindow", "ptr", hwnd, "uint", 3, "ptr")
        Loop, 4
            DllCall(    "SetWindowPos", "ptr", this[A_Index], "ptr", ABOVE
                    ,    "int", 0, "int", 0, "int", 0, "int", 0
                    ,    "uint", 0x1|0x2|0x10    )
    }
    Transparent(param) {
        Loop, 4
            WinSet, Transparent, % param=1? 0:255, % "ahk_id" this[A_Index]
        this.isVisible := !param
    }
    Color(color) {
        Gui, +HWNDdefault
        Loop, 4
            Gui, % this[A_Index] ": Color" , %color%
        this.color := color
        Gui, %default%: Default
    }
    Destroy() {
        Loop, 4
            Gui, % this[A_Index] ": Destroy"
    }
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他应用教程案例

超级命令【super-command】

2021-12-16 22:02:50

其他

v1中文字符串过滤

2021-12-20 16:34:58

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索