应用窗口置顶且加边框提醒

应用窗口置顶且加边框提醒

;按f2直接运行效果
;----------------窗口边界框--------------
Class HighlightOutline
{
	__New(color="red", Transparent=255)
	{
		loop 4
		{
			Gui New, -Caption +AlwaysOnTop +ToolWindow HWNDhwnd -DPIScale +E0x20 +E0x00080000
			Gui Color, %color%
			DllCall("SetLayeredWindowAttributes", "Ptr", this[A_Index] := hwnd, "Uint", 0,"Uchar", Transparent, "int", 2)
		}
		this.top := this[1]
    , this.right := this[2]
    , this.bottom := this[3]
    , this.left := this[4]
		Gui % "Gui_Cheek_Number" A_DefaultGui ": default"
	}
	Show(x1, y1, x2, y2, b=3)
  {
    Try
    {
      Gui % this.1 ":Show", % "NA x" x1-b " y" y1-b " w" x2-x1+b*2 " h" b
      Gui % this.2 ":Show", % "NA x" x2 " y" y1 " w" b " h" y2-y1
      Gui % this.3 ":Show", % "NA x" x1-b " y" y2 " w" x2-x1+2*b " h" b
      Gui % this.4 ":Show", % "NA x" x1-b " y" y1 " w" b " h" y2-y1
    }
  }
  Hide()
  {
    loop 4
      Try Gui % this[A_Index] ": Hide"
  }
  Destroy()
  {
    loop 4
      Try Gui % this[A_Index] ": Destroy"
  }
}

;当全局变量
active_window_Array := []
active_win :=["h1","h2","h3","h4","h5","h6","h7","h8"]


;---执行快捷键-(可修改)---
f2::
{
  WinGet ow, id, A
  WinTopToggle(ow,active_window_Array,active_win)
  return
}

WinTopToggle(w,active_window_Array,active_win) {
 
    WinGetTitle, oTitle, ahk_id %w%
    Winset, AlwaysOnTop, Toggle, ahk_id %w%
    WinGet, ExStyle, ExStyle, ahk_id %w%
    if (ExStyle & 0x8)  ; 0x8 为 WS_EX_TOPMOST.在WinGet的帮助中
    {
      oTop = 置顶
      ;-------窗口边框-------------
      WinGetActiveStats, Title, Width, Height, X, Y

      ;MsgBox % active_window_Array.Length()
      if (active_window_Array.Length() == 0)  ;特殊情况
      {
        active_window_Array.Push(Title)
      }
      Flag := 0
      ;MsgBox % active_window_Array.Length()
      for index,Value in active_window_Array
      {
        if(Value == Title)  ;如果是同一个窗口 就关闭之前的边界框 
        {
          active_win[index].Destroy()  
          break
        }
        if (index == active_window_Array.Length())  ;窗口数组中没有这个窗口,就添加新的窗口对象
        {
          active_window_Array.Push(Title)
          Flag := 1
        }
      }
      ;MsgBox %Flag%, "index",%index%
      if(Flag == 0)  ;已有窗口
      {
        active_win[index] := new HighlightOutline("red",255)
        active_win[index].Show(X+1,Y+1,X+Width-1,Y+Height-1)
      }
      else  ;新窗口
      {
        active_win[active_window_Array.Length()] := new HighlightOutline("red",255)
        active_win[active_window_Array.Length()].Show(X+1,Y+1,X+Width-1,Y+Height-1)
        Flag := 0
      }
      ;-------窗口边框-------------
      ;MsgBox % active_window_Array[1]
    }
    else
    {
      oTop = 取消置顶
      ;-------窗口消失---------------
      WinGetActiveStats, Title, Width, Height, X, Y
      for index,Value in active_window_Array
      {
        if(Value == Title)
        {
          active_win[index].Destroy()
          active_window_Array.Delete(index)
          break
        }
      }  
      ;-------窗口消失---------------
    }
    tooltip %oTitle% %oTop%
    SetTimer, RemoveToolTip, 1500
    return
 
    RemoveToolTip:
    SetTimer, RemoveToolTip, Off
    ToolTip
    return
}

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

[第1001关] 极速构建一个输出热字符串输出的形码输入法

2022-5-23 9:13:24

其他

隐式等待 代替sleep

2022-5-25 15:35:45

3 条回复 A文章作者 M管理员
  1. AHK中文社区

    建议增加描述和演示。只有代码很难一下看到效果。

  2. AHK中文社区
    1河许人给您打赏了¥2
  3. dbgba
    dbgba给您打赏了¥2
个人中心
购物车
优惠劵
有新私信 私信列表
搜索