# 高亮当前窗口

**URL:** <https://meta.appinn.net/t/topic/50188>\
**Category:** 问题求助\
**Tags:** autohotkey, windows\
**Created:** [2023 年12 月 9 日 14:56 UTC](https://meta.appinn.net/t/topic/50188 "2023-12-09T14:56:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ico](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/i/91b2a8/32.png) [@ico](https://meta.appinn.net/u/ico)\
**Post date:** [2023 年12 月 9 日 14:56 UTC](https://meta.appinn.net/t/topic/50188/1 "2023-12-09T14:56:23Z")

</div>

# 需求

能够高亮当前窗口边框（像OBS选择窗口对象录屏时出现的这种边框效果），或者调暗非活动窗口。Windows自带的这种标题栏变暗的效果太不明显了，而且视频全屏（外接了一个屏幕，所以两个窗口能分别在两个屏幕上）的时候更是不方便  
不知道AHK能实现这种效果吗？论坛里的手搓大佬们是否有过这种想法？

OBS选择窗口录屏出现边框效果提示：

 ![image](https://meta-edge.appinn.com/uploads/default/original/3X/7/b/7b97c903030ee17e6be56ba1384bcf67d2c16c9e.png)

OBS不选择该窗口：

 ![image](https://meta-edge.appinn.com/uploads/default/original/3X/4/9/498373ad5219e1bb75f3671a78b48263a071030e.png)

# 场景

经常在两个窗口间来回切换，比如一个浏览器窗口看着视频，一个笔记窗口记着笔记，但有时候又会切到第三个窗口，导致窗口顺序打乱，Alt-Tab之后想用快捷键调视频进度/播放/速度，却发现实际到了别的窗口，而自己却要等个几秒才能反应过来，这种体验很不爽

---

<div class="post-metadata">

**Author:** ![dog](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/dog/32/18667_2.png) [@dog](https://meta.appinn.net/u/dog)\
**Post date:** [2023 年12 月 10 日 02:12 UTC](https://meta.appinn.net/t/topic/50188/2 "2023-12-10T02:12:36Z")

</div>

这种不冷门的问题，在autohotkey论坛一搜就有了。  
[在活动窗口 V2 周围绘制边框？- AutoHotkey 社区](https://www.autohotkey.com/boards/viewtopic.php?f=82&t=123868)

```auto
; V1 ======================================
SetTimer, DrawRect, 100
; DrawRect()
; windows in windows 10 has thick invisible boarder which is about 4 pixels wide.
DrawRect:
    border_thickness = 3
    ; set the color of the border
    border_color = red
    ; set the color of the border
    ; Get the current window's position
    ; WinWaitActive ahk_class PotPlayer64
    WinGetPos, x, y, w, h, A
    ; WinGetPos, x, y, w, h, A
    ; To avoid the error message
    if (x="")
        return
    ;Gui, +Lastfound +AlwaysOnTop +Toolwindow
    Gui, +Lastfound +AlwaysOnTop
    ; set the background for the GUI window
    Gui, Color, %border_color%
    ; remove thick window border of the GUI window
    Gui, -Caption
    ; Retrieves the minimized/maximized state for a window.
    WinGet, notMedium , MinMax, A
    if (notMedium==0){
        ; 0: The window is neither minimized nor maximized.
        offset:=0
        outerX:=offset
        outerY:=offset
        outerX2:=w-offset
        outerY2:=h-offset
        innerX:=border_thickness+offset
        innerY:=border_thickness+offset
        innerX2:=w-border_thickness-offset
        innerY2:=h-border_thickness-offset
        newX:=x
        newY:=y
        newW:=w
        newH:=h
        WinSet, Region, %outerX%-%outerY% %outerX2%-%outerY% %outerX2%-%outerY2% %outerX%-%outerY2% %outerX%-%outerY% %innerX%-%innerY% %innerX2%-%innerY% %innerX2%-%innerY2% %innerX%-%innerY2% %innerX%-%innerY%
        Gui, Show, w%newW% h%newH% x%newX% y%newY% NoActivate, GUI4Boarder
        return
    } else {
        WinSet, Region, 0-0 w0 h0
        return
    }
return

```

```auto
#Requires AutoHotkey v2
; V2 ======================================
;Gui, +Lastfound +AlwaysOnTop +Toolwindow
border_thickness := 3
border_color := 'red'
; set the background for the GUI window
G := Gui('+Lastfound +AlwaysOnTop -Caption')
; set the color of the border
G.BackColor := border_color
; remove thick window border of the GUI window
G.Opt('-Caption')
SetTimer(DrawRect, 100)
; DrawRect()
; windows in windows 10 has thick invisible boarder which is about 4 pixels wide.
DrawRect() {
	; set the color of the border
	; Get the current window's position
	; WinWaitActive ahk_class PotPlayer64
	Try
		WinGetPos(&x, &y, &w, &h, 'A')
	Catch As Err {
		Return
	}
	; WinGetPos, x, y, w, h, A
	; To avoid the error message
	; Retrieves the minimized/maximized state for a window.
	notMedium := WinGetMinMax('A')
	if (notMedium == 0) {
		; 0: The window is neither minimized nor maximized.
		offset := 0
		outerX := offset
		outerY := offset
		outerX2 := w - offset
		outerY2 := h - offset
		innerX := border_thickness + offset
		innerY := border_thickness + offset
		innerX2 := w - border_thickness - offset
		innerY2 := h - border_thickness - offset
		newX := x
		newY := y
		newW := w
		newH := h
		WinSetRegion(outerX '-' outerY ' ' outerX2 '-' outerY ' ' outerX2 '-' outerY2 ' ' outerX '-' outerY2 ' ' outerX '-' outerY ' ' innerX '-' innerY ' ' innerX2 '-' innerY ' ' innerX2 '-' innerY2 ' ' innerX '-' innerY2 ' ' innerX '-' innerY, G)
		;WinSet, Region, outerX-outerY outerX2-outerY outerX2-outerY2 outerX-outerY2 outerX-outerY innerX-innerY innerX2-innerY innerX2-innerY2 innerX-innerY2 innerX-innerY
		G.Show('w' newW ' h' newH ' x' newX ' y' newY ' NoActivate')
		;Gui, Show, wnewW hnewH xnewX ynewY NoActivate, GUI4Boarder
	} else {
		WinSetRegion('0-0 w0 h0', G)
	}
}

```

---

<div class="post-metadata">

**Author:** ![ico](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/i/91b2a8/32.png) [@ico](https://meta.appinn.net/u/ico)\
**Post date:** [2023 年12 月 10 日 06:54 UTC](https://meta.appinn.net/t/topic/50188/3 "2023-12-10T06:54:23Z")

</div>

有办法隐藏掉这个AHK的窗口吗？  
任务栏会显示这个AHK任务  
 ![image](https://meta.appinn.net/uploads/default/original/3X/a/d/adb51e70b38cdb1f5470a199dc36fd1b7d6d0807.png)

Alt-Tab切换界面也会显示

 ![image](https://meta.appinn.net/uploads/default/original/3X/b/b/bbc38606a72e7e74a76e80d3a0d44b010cd680dd.jpeg)

---

<div class="post-metadata">

**Author:** ![dog](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/dog/32/18667_2.png) [@dog](https://meta.appinn.net/u/dog)\
**Post date:** [2023 年12 月 10 日 06:56 UTC](https://meta.appinn.net/t/topic/50188/4 "2023-12-10T06:56:40Z")

</div>

```auto
    Gui, +Lastfound +AlwaysOnTop

```

改成

` Gui, +Lastfound +AlwaysOnTop +Toolwindow`

v2版的这句里加  
`G := Gui('+Lastfound +AlwaysOnTop -Caption +Toolwindow')`
