ControlSetStyle / ControlSetExStyle

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

ControlSetStyle Value, Control , WinTitle, WinText, ExcludeTitle, ExcludeText
ControlSetExStyle Value, Control , 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 ControlGetStyle/ControlGetExStyle or 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.

Control

Type: String, Integer or Object

The control's ClassNN, text or HWND, or an object with a Hwnd property. For details, see The Control Parameter.

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 or control could not be found or the style could not be changed. Partial change is considered a success.

Remarks

See the styles table for a partial listing of styles.

Certain style changes require that the entire window be redrawn using WinRedraw.

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

Related

ControlGetStyle / ControlGetExStyle, WinSetStyle / WinSetExStyle, styles table, Control functions

Examples

#1: Sets the WS_BORDER style of the Notepad's Edit control to its opposite state:

ControlSetStyle("^0x800000", "Edit1", "ahk_class Notepad")