Skip to content

Instantly share code, notes, and snippets.

@pa-0
Forked from ericreeves/active_border.ahk
Last active October 12, 2025 00:45
Show Gist options
  • Save pa-0/2cb96aabfce2ac1d2d2adeb7da4d4b4b to your computer and use it in GitHub Desktop.
Save pa-0/2cb96aabfce2ac1d2d2adeb7da4d4b4b to your computer and use it in GitHub Desktop.

Revisions

  1. pa-0 revised this gist Oct 12, 2025. 2 changed files with 70 additions and 27 deletions.
    54 changes: 54 additions & 0 deletions active_border-ah1.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #Requires AutoHotkey v1
    ; Inspiration / Code Jacked from the following resources:
    ; https://www.reddit.com/r/windowsporn/comments/x6299x/a_small_effect_on_window_switching/
    ; https://superuser.com/questions/1190658/fine-tune-this-red-border-around-active-window-ahk-script/1191059#1191059?newreg=d3acdcdab8714e76a5efeca9996e792f
    ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=110505
    ; https://discord.com/channels/898554690126630914/898556726108901386/1053662963585781760 # Komorebi Discord
    ;

    #NoEnv
    #SingleInstance, Force
    #Persistent
    SendMode, Input
    SetBatchLines, -1
    SetWorkingDir, %A_ScriptDir%

    Gui +LastFound
    hWnd := WinExist()
    DllCall("RegisterShellHookWindow", UInt,hWnd)
    MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
    OnMessage(MsgNum, "ShellMessage")
    Return

    ShellMessage(wParam,lParam) {
    Local k
    if (wParam = 32772){
    SetTimer, DrawActive, -1
    }
    }

    DrawActive:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Border Color Configuration
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    border_color := "0x6238FF"
    ; Start by removing the borders from all windows, since we do not know which window was previously active
    WinGet, WindowHandles, List
    loop % WindowHandles
    {
    DrawBorder(WindowHandles%A_Index%, , 0)
    }
    ; Draw the border around the active window
    hwnd := WinExist("A")
    DrawBorder(hwnd, border_color, 1)
    Return

    DrawBorder(hwnd, color:=0xFF0000, enable:=1) {
    static DWMWA_BORDER_COLOR := 34
    static DWMWA_COLOR_DEFAULT := 0xFFFFFFFF
    R := (color & 0xFF0000) >> 16
    G := (color & 0xFF00) >> 8
    B := (color & 0xFF)
    color := (B << 16) | (G << 8) | R
    DllCall("dwmapi\DwmSetWindowAttribute", "ptr", hwnd, "int", DWMWA_BORDER_COLOR, "int*", enable ? color : DWMWA_COLOR_DEFAULT, "int", 4)
    }
    43 changes: 16 additions & 27 deletions active_border.ahk
    Original file line number Diff line number Diff line change
    @@ -1,47 +1,36 @@
    ;
    ; Inspiration / Code Jacked from the following resources:
    ; https://www.reddit.com/r/windowsporn/comments/x6299x/a_small_effect_on_window_switching/
    ; https://superuser.com/questions/1190658/fine-tune-this-red-border-around-active-window-ahk-script/1191059#1191059?newreg=d3acdcdab8714e76a5efeca9996e792f
    ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=110505
    ; https://discord.com/channels/898554690126630914/898556726108901386/1053662963585781760 # Komorebi Discord
    ;
    #Requires AutoHotkey v2.0
    #SingleInstance Force

    #NoEnv
    #SingleInstance, Force
    #Persistent
    SendMode, Input
    SetBatchLines, -1
    SetWorkingDir, %A_ScriptDir%

    Gui +LastFound
    myGui := Gui()
    myGui.Opt("+LastFound")
    hWnd := WinExist()
    DllCall("RegisterShellHookWindow", UInt,hWnd)
    MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
    OnMessage(MsgNum, "ShellMessage")
    Return
    DllCall("RegisterShellHookWindow", "UInt", hWnd)
    MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
    OnMessage(MsgNum, ShellMessage)
    Persistent

    ShellMessage(wParam,lParam) {
    Local k
    ShellMessage(wParam,lParam, msg, hwnd) {
    if (wParam = 32772){
    SetTimer, DrawActive, -1
    SetTimer(DrawActive,-1)
    }
    }

    DrawActive:
    DrawActive()
    {
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Border Color Configuration
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    border_color := "0x6238FF"
    ; Start by removing the borders from all windows, since we do not know which window was previously active
    WinGet, WindowHandles, List
    loop % WindowHandles
    windowHandles := WinGetList(,,,)
    For handle in windowHandles
    {
    DrawBorder(WindowHandles%A_Index%, , 0)
    DrawBorder(handle, , 0)
    }
    ; Draw the border around the active window
    hwnd := WinExist("A")
    DrawBorder(hwnd, border_color, 1)
    Return
    }

    DrawBorder(hwnd, color:=0xFF0000, enable:=1) {
    static DWMWA_BORDER_COLOR := 34
  2. @ericreeves ericreeves revised this gist Jan 1, 2023. No changes.
  3. @ericreeves ericreeves revised this gist Jan 1, 2023. No changes.
  4. @ericreeves ericreeves revised this gist Jan 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion active_border.ahk
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ DrawActive:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Border Color Configuration
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    border_color := "0x89B4FA"
    border_color := "0x6238FF"
    ; Start by removing the borders from all windows, since we do not know which window was previously active
    WinGet, WindowHandles, List
    loop % WindowHandles
  5. @ericreeves ericreeves created this gist Jan 1, 2023.
    54 changes: 54 additions & 0 deletions active_border.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    ;
    ; Inspiration / Code Jacked from the following resources:
    ; https://www.reddit.com/r/windowsporn/comments/x6299x/a_small_effect_on_window_switching/
    ; https://superuser.com/questions/1190658/fine-tune-this-red-border-around-active-window-ahk-script/1191059#1191059?newreg=d3acdcdab8714e76a5efeca9996e792f
    ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=110505
    ; https://discord.com/channels/898554690126630914/898556726108901386/1053662963585781760 # Komorebi Discord
    ;

    #NoEnv
    #SingleInstance, Force
    #Persistent
    SendMode, Input
    SetBatchLines, -1
    SetWorkingDir, %A_ScriptDir%

    Gui +LastFound
    hWnd := WinExist()
    DllCall("RegisterShellHookWindow", UInt,hWnd)
    MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
    OnMessage(MsgNum, "ShellMessage")
    Return

    ShellMessage(wParam,lParam) {
    Local k
    if (wParam = 32772){
    SetTimer, DrawActive, -1
    }
    }

    DrawActive:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Border Color Configuration
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    border_color := "0x89B4FA"
    ; Start by removing the borders from all windows, since we do not know which window was previously active
    WinGet, WindowHandles, List
    loop % WindowHandles
    {
    DrawBorder(WindowHandles%A_Index%, , 0)
    }
    ; Draw the border around the active window
    hwnd := WinExist("A")
    DrawBorder(hwnd, border_color, 1)
    Return

    DrawBorder(hwnd, color:=0xFF0000, enable:=1) {
    static DWMWA_BORDER_COLOR := 34
    static DWMWA_COLOR_DEFAULT := 0xFFFFFFFF
    R := (color & 0xFF0000) >> 16
    G := (color & 0xFF00) >> 8
    B := (color & 0xFF)
    color := (B << 16) | (G << 8) | R
    DllCall("dwmapi\DwmSetWindowAttribute", "ptr", hwnd, "int", DWMWA_BORDER_COLOR, "int*", enable ? color : DWMWA_COLOR_DEFAULT, "int", 4)
    }