# Function Reference

# _WinAPI_SetWindowTheme

Causes a window to use a different set of visual style information than its class normally uses

#include <WinAPITheme.au3>
_WinAPI_SetWindowTheme ( $hWnd [, $sName = Default [, $sList = Default]] )

## Parameters

$hWnd | Handle to the window whose visual style information is to be changed.
$sName | [optional] A string that contains the application name. If this parameter is 0 (Default), the calling application's name is used.
$sList | [optional] A string that contains a semicolon-separated list of CLSID names to use in place of the actual list passed by the window's class. If this parameter is 0 (Default), the ID list from the calling class is used.

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the HRESULT error code.

## Remarks

The theme manager retains the $sName and the $sList associations through the lifetime of the window, even
if visual styles subsequently change.
When $sName and $sList are Default, the theme manager removes the previously applied associations.
To prevent visual styles from being applied to a specified window, add a _WinAPI_SetWindowTheme($hWnd, "", "") which will not match any section entries.

## See Also

Search SetWindowTheme in MSDN Library.

## Example

### Example 1

    #include <GUIConstantsEx.au3>
    #include <MsgBoxConstants.au3>
    #include <WinAPISys.au3>
    #include <WinAPITheme.au3>

    If Number(_WinAPI_GetVersion()) < 6.0 Then
        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Require Windows Vista or later.')
        Exit
    EndIf

    GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 332, 400)

    Local $idListview = GUICtrlCreateListView('Column 1|Column 2|Column 3|Column 4', 10, 10, 312, 380)
    For $i = 1 To 9
        GUICtrlCreateListViewItem('Item ' & $i & '|' & 'Sub ' & $i & '|' & 'Sub ' & $i & '|' & 'Sub ' & $i, $idListview)
    Next

    _WinAPI_SetWindowTheme(GUICtrlGetHandle($idListview), 'Explorer')

    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

### Example 2 - use of "", "" or _WinAPI_SetThemeAppProperties(0) to color Checkbox or Radio

    #include <APIThemeConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPITheme.au3>

    Example()

    Func Example()

        GUICreate("_WinAPI_SetWindowTheme (v" & @AutoItVersion & ")", 430, 240)
        GUICtrlCreateLabel(' ThemeAppProperties = "' & GetThemeAppPropertiesToString() & '"', 10, 10, 420)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " No Color", 10, NextHeight(30), 400)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set color by AutoIt", 10, NextHeight(), 400)
        GUICtrlSetColor(-1, 0xFF0000)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set Window Theme no param", 10, NextHeight(), 400)
        _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1))
        GUICtrlSetColor(-1, 0xFF0000)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set Window Theme with Default, Default", 10, NextHeight(), 400)
        _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), Default, Default)
        GUICtrlSetColor(-1, 0xFF0000)

        GUICtrlCreateCheckbox(@ScriptLineNumber & ' Set Window Theme "", "" MSDN', 10, NextHeight(), 400)
        _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), "", "")
        GUICtrlSetColor(-1, 0xFF0000)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set Window Theme with  Null, Null", 10, NextHeight(), 400)
        _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), Null, Null)
        GUICtrlSetColor(-1, 0xFF00FF)

        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set Window Theme with  0, 0 >>> 0 = Null >>> ", 10, NextHeight(), 400)
        _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), 0, 0)
        GUICtrlSetColor(-1, 0xFF00FF)

        _WinAPI_SetThemeAppProperties(0)
        NextHeight()
        GUICtrlCreateLabel(' ThemeAppProperties after SetThemeAppProperties(0) = "' & GetThemeAppPropertiesToString() & '"', 10, NextHeight(), 420)
        GUICtrlCreateCheckbox(@ScriptLineNumber & " Set color by AutoIt with _WinAPI_SetThemeAppProperties(0)", 10, NextHeight(), 400)
        GUICtrlSetColor(-1, 0xFF0000)

        GUISetState()

        While GUIGetMsg() <> $GUI_EVENT_CLOSE
            Sleep(50)
        WEnd

        GUIDelete()
    EndFunc   ;==>Example

    Func GetThemeAppPropertiesToString($iProperties = Default)
        If $iProperties = Default Then $iProperties = _WinAPI_GetThemeAppProperties()

        Local $sProperties = ""
        If BitAnd($iProperties, $STAP_ALLOW_CONTROLS) Then $sProperties &= "STAP_ALLOW_CONTROLS,"
        If BitAnd($iProperties, $STAP_ALLOW_NONCLIENT) Then $sProperties &= "STAP_ALLOW_NONCLIENT,"
        If BitAnd($iProperties, $STAP_ALLOW_WEBCONTENT) Then $sProperties &= "$STAP_ALLOW_WEBCONTENT,"

        Return StringTrimRight($sProperties, 1)
    EndFunc   ;==>GetThemeAppPropertiesToString

    Func NextHeight($iInit = Default)
        Local Static $iNext = 0
        If $iInit = Default Then
            $iNext += 20
        Else
            $iNext = $iInit
        EndIf
        Return $iNext
    EndFunc