WinSetStyle / WinSetExStyle

Changes the style or extended style of the specified window, respectively.

WinSetStyle Value , WinTitle, WinText, ExcludeTitle, ExcludeText
WinSetExStyle Value , WinTitle, WinText, ExcludeTitle, ExcludeText

Parameters

Value

Type: Integer or String

Pass a positive integer to completely overwrite the window's style; that is, to set it to Value.

To easily add, remove or toggle styles, pass a numeric string prefixed with a plus sign (+), minus sign (-) or caret (^), respectively. The new style value is calculated as shown below (where CurrentStyle could be retrieved with WinGetStyle/WinGetExStyle):

Operation Prefix Example String Formula
Add + +0x80 NewStyle := CurrentStyle | Value
Remove - -0x80 NewStyle := CurrentStyle & ~Value
Toggle ^ ^0x80 NewStyle := CurrentStyle ^ Value

If Value is a negative integer, it is treated the same as the corresponding numeric string.

To use the + or ^ prefix literally in an expression, the prefix or value must be enclosed in quote marks. For example: WinSetStyle("+0x80") or WinSetStyle("^" StylesToToggle). This is because the expression +123 produces 123 (without a prefix) and ^123 is a syntax error.

WinTitle

Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.

WinText

Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.

ExcludeTitle

Type: String

Windows whose titles include this value will not be considered.

ExcludeText

Type: String

Windows whose text include this value will not be considered.

Error Handling

An exception is thrown if the window could not be found or the change could not be applied.

Remarks

See the styles table for a partial listing of styles.

After applying certain style changes to a visible window, it might be necessary to redraw the window using WinRedraw.

The ID of the window under the mouse cursor can be retrieved with MouseGetPos.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

Related

WinGetStyle / WinGetExStyle, ControlSetStyle / ControlSetExStyle, styles table, Win functions, Control functions

Examples

#1: Removes the active window's title bar (WS_CAPTION):

WinSetStyle "-0xC00000", "A"

#1: Toggles the WS_EX_TOOLWINDOW attribute, which removes/adds Notepad from the alt-tab list:

WinSetExStyle "^0x80", "ahk_class Notepad"