Last active
August 11, 2024 21:08
-
-
Save nperovic/a1de67617f9154038ab46873092647fd to your computer and use it in GitHub Desktop.
Set the color of a window's caption, text, or border. This is supported starting with Windows 11 Build 22000.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires AutoHotkey v2 | |
/** | |
* Sets the attributes of a window. Specifically, it can set the color of the window's caption, text, and border. | |
* @param {integer} hwnd Window handle. | |
* @param {integer} [titleText] Specifies the color(BGR) of the caption text. Specifying `0xFFFFFFFF` will reset to the system's default caption text color. | |
* @param {integer} [titleBackground] Specifies the color(BGR) of the caption. Specifying `0xFFFFFFFF` will reset to the system's default caption color. | |
* @param {integer} [border] Specifies the color(BGR) of the window border. | |
* - Specifying `0xFFFFFFFE` will suppress the drawing of the window border. | |
* - Specifying `0xFFFFFFFF` will reset to the system's default border color. | |
* The application is responsible for changing the border color in response to state changes, such as window activation. | |
* @since This is supported starting with Windows 11 Build 22000. | |
* @returns {String} - The result of the attribute setting operation. | |
*/ | |
SetWindowColor(hwnd, titleText?, titleBackground?, border?) | |
{ | |
static DWMWA_BORDER_COLOR := 34 | |
static DWMWA_CAPTION_COLOR := 35 | |
static DWMWA_TEXT_COLOR := 36 | |
if (VerCompare(A_OSVersion, "10.0.22200") < 0) | |
return MsgBox("This is supported starting with Windows 11 Build 22000.", "OS Version Not Supported.") | |
if (border??0) | |
DwmSetWindowAttribute(hwnd, DWMWA_BORDER_COLOR, border) | |
if (titleBackground??0) | |
DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, titleBackground) | |
if (titleText??0) | |
DwmSetWindowAttribute(hwnd, DWMWA_TEXT_COLOR, titleText) | |
DwmSetWindowAttribute(hwnd?, dwAttribute?, pvAttribute?) => DllCall("Dwmapi\DwmSetWindowAttribute", "Ptr" , hwnd, "UInt", dwAttribute, "Ptr*", &pvAttribute, "UInt", 4) | |
} |
RGB to BGR
RgbToBgr(color) => ((Color >> 16) & 0xFF) | (Color & 0x00FF00) | ((Color & 0xFF) << 16)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
Set a custom color to the active window.
Reset the color.
Note
Color format: BGR