指示窗口“始终位于最前”

指示窗口“始终位于最前”

大家好!我想给始终位于最上方的窗口添加红色边框/阴影以识别其状态。目前,我识别它的方法是降低不透明度。有什么建议吗?谢谢

#SingleInstance, force

^f::
WinGetActiveTitle, Title
    WinGet, ExStyle, ExStyle, % Title
        if (ExStyle & 0x8){
            WinSet, AlwaysOnTop, Off, % Title
            WinSet, Transparent, 255, % Title
        } else {
            WinSet, AlwaysOnTop, On , % Title
            WinSet, Transparent, 230, % Title
        }
    Return

我的 Windows 版本:Windows 10 版本 21H2

答案1

解决方案:

#SingleInstance, force
^f::
SetTimer, CheckBorder, 500, -10
Id := WinActive("A"), t := 4 ; t = border thickness
WinGet, ExStyle, ExStyle, ahk_id %Id%
if (ExStyle & 0x8)
{
    WinSet, AlwaysOnTop, Off, ahk_id %Id%
    WinClose,% "ahk_id " Red%ID%
    WinIDs := StrReplace(WinIDs, "," ID), Red%ID% := ""
    Return
}
WinSet, AlwaysOnTop, On , ahk_id %Id%
MakeBorder:
WinGetpos, x, y, w, h, ahk_id %Id%
Gui, New, +ToolWindow -Caption +LastFound +AlwaysOnTop +E0x20 +HwndRed
Gui, Color, Red
WinSet, Region,% "0-0 "w "-0 "w "-"h " 0-"h " 0-0 "t "-"t " "w-t "-"t " "w-t "-"h-t " "t "-"h-t " "t "-"t
Gui, Show, x%x% y%y% w%w% h%h% NoActivate
Red%ID% := Red, Pos%ID% := x y w h, WinIDs .= "," ID
Return
CheckBorder:
DetectHiddenWindows, On
Loop, Parse, WinIDs, CSV
{
    IF !ID := A_LoopField
        Continue
    IF !WinExist("ahk_id " ID)
    {
        WinClose,% "ahk_id " Red%ID%
        WinIDs := StrReplace(WinIDs, "," ID), Red%ID% := ""
        Break
    }
    WinGetpos, x, y, w, h, ahk_id %ID%
    IF (x y w h) = Pos%ID%
        Continue
    WinClose,% "ahk_id " Red%ID%
    WinIDs := StrReplace(WinIDs, "," ID), Red%ID% := ""
    Goto, MakeBorder
}
Return

相关内容