Function Reference


_WinAPI_DwmSetWindowAttribute

Sets the value of the specified attributes for non-client rendering to apply to the window

#include <WinAPIGdi.au3>
_WinAPI_DwmSetWindowAttribute ( $hWnd, $iAttribute, $iData )

Parameters

$hWnd The window handle to apply the given attribute.
$iAttribute The attribute to apply to the window. This parameter can be one of the following values:
    $DWMWA_NCRENDERING_POLICY (2)
        Sets the non-client rendering policy.
        $iData is a value from the DWMNCRENDERINGPOLICY enumeration:
            $DWMNCRP_USEWINDOWSTYLE
                The non-client rendering area is rendered based on the window style.
            $DWMNCRP_DISABLED
                The non-client area rendering is disabled; the window style is ignored.
            $DWMNCRP_ENABLED
                The non-client area rendering is enabled; the window style is ignored.
    $DWMWA_TRANSITIONS_FORCEDISABLED (3)
        Enables or forcibly disables DWM transitions.
        $iData is a value of type BOOL.
        TRUE to disable transitions, or FALSE to enable transitions.
    $DWMWA_ALLOW_NCPAINT (4)
        Enables content rendered in the non-client area to be visible on the frame drawn by DWM.
        $iData is a value of type BOOL.
        TRUE to enable content rendered in the non-client area to be visible on the frame; otherwise, FALSE
    $DWMWA_NONCLIENT_RTL_LAYOUT (6)
        Specifies whether non-client content is right-to-left (RTL) mirrored.
        $iData is a value of type BOOL. TRUE if the non-client content is right-to-left (RTL) mirrored; otherwise, FALSE.
    $DWMWA_FORCE_ICONIC_REPRESENTATION (7)
        Forces the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot representation of the window is available.
        $iData is a value of type BOOL.
        TRUE to require a iconic thumbnail or peek representation; otherwise, FALSE.

        This value is normally set during a window's creation, and not changed throughout the window's lifetime.
        Some scenarios, however, might require the value to change over time.
    $DWMWA_FLIP3D_POLICY (8)
        Sets how Flip3D treats the window.
        $iData is a value from the DWMFLIP3DWINDOWPOLICY enumeration:
            $DWMFLIP3D_DEFAULT
                Use the window's style and visibility settings to determine whether to hide or include the window in Flip3D rendering.
            $DWMFLIP3D_EXCLUDEBELOW
                Exclude the window from Flip3D and display it below the Flip3D rendering.
            $DWMFLIP3D_EXCLUDEABOVE
                Exclude the window from Flip3D and display it above the Flip3D rendering.

Windows Vista or later
    $DWMWA_HAS_ICONIC_BITMAP (10)
        The window will provide a bitmap for use by DWM as an iconic thumbnail or peek representation (a static bitmap) for the window.
        $iData is a value of type BOOL.
        TRUE to inform DWM that the window will provide an iconic thumbnail or peek representation; otherwise, FALSE.

        DWMWA_HAS_ICONIC_BITMAP can be specified with DWMWA_FORCE_ICONIC_REPRESENTATION.
        DWMWA_HAS_ICONIC_BITMAP normally is set during a window's creation and not changed throughout the window's lifetime.
        Some scenarios, however, might require the value to change over time.
    $DWMWA_DISALLOW_PEEK (11)
        Do not show peek preview for the window.
        $iData is a value of type BOOL. TRUE to prevent peek functionality, or FALSE to allow it.

        The peek view shows a full-sized preview of the window when the mouse hovers over the window's thumbnail in the taskbar.
        If this attribute is set, hovering the mouse pointer over the window's thumbnail dismisses peek (in case another window in the group has a peek preview showing).

    $DWMWA_EXCLUDED_FROM_PEEK (12)
        Prevents a window from fading to a glass sheet when peek is invoked.
        $iData is a value of type BOOL.
        TRUE to prevent the window from fading during another window's peek, or FALSE for normal behavior.

Windows 7 or later
    $DWMWA_CLOAK (13)
        Cloaks the window such that it is not visible to the user. The window is still composed by DWM.
        Using with DirectComposition: Use the DWMWA_CLOAK flag to cloak the layered child window when animating a representation of the window's content via a DirectComposition visual that has been associated with the layered child window.
        For more details on this usage case, see How to animate the bitmap of a layered child window.
    $DWMWA_FREEZE_REPRESENTATION (15)
        Freeze the window's thumbnail image with its current visuals.
        Do no further live updates on the thumbnail image to match the window's contents.
    $DWMWA_PASSIVE_UPDATE_MODE (16) (not documented in MSDN)
        $iData is a value of type BOOL.
        TRUE to Set passive mode or FALSE otherwise.

Windows 11 (@OSBuild = 22000) or later
    $DWMWA_USE_HOSTBACKDROPBRUSH (17)
        Enables a non-UWP window to use host backdrop brushes.
        $iData is a value of type BOOL.
        TRUE to enable host backdrop brushes for the window, or FALSE to disable it.

        If this flag is set, then a Win32 app that calls Windows::UI::Composition APIs can build transparency effects using the host backdrop brush (see Compositor.CreateHostBackdropBrush).
    $DWMWA_USE_IMMERSIVE_DARK_MODE (20)
        Allows the window frame for this window to be drawn in dark mode colors when the dark mode system setting is enabled.
        $iData is a value of type BOOL.
        TRUE to honor dark mode for the window, FALSE to always use light mode.

        For compatibility reasons, all windows default to light mode regardless of the system setting.
    $DWMWA_WINDOW_CORNER_PREFERENCE (33)
        Specifies the rounded corner preference for a window.
        $iData is a value of type DWM_WINDOW_CORNER_PREFERENCE:
            DWMWCP_DEFAULT
                Let the system decide when to round window corners.
            $DWMWCP_DONOTROUND
                Never round window corners.
            $DWMWCP_ROUND
                Round the corners, if appropriate.
            $DWMWCP_ROUNDSMALL
                Round the corners if appropriate, with a small radius.
    $DWMWA_BORDER_COLOR (34)
        Specifies the color of the window border.
        $iData is a value of type COLORREF. The app is responsible for changing the border color according to state changes, such as a change in window activation.

        Specifying DWMWA_COLOR_NONE (value 0xFFFFFFFE) for the color will suppress the drawing of the window border.
        This makes it possible to have a rounded window with no border.

        Specifying DWMWA_COLOR_DEFAULT (value 0xFFFFFFFF) for the color will reset the window back to using the system's default behavior for the border color.
    $DWMWA_CAPTION_COLOR (35)
        Specifies the color of the caption.
        $iData is a value of type COLORREF.

        Specifying DWMWA_COLOR_DEFAULT (value 0xFFFFFFFF) for the color will reset the window back to using the system's default behavior for the caption color.
    $DWMWA_TEXT_COLOR (36)
        Specifies the color of the caption text.
        $iData is a value of type COLORREF.

        Specifying DWMWA_COLOR_DEFAULT (value 0xFFFFFFFF) for the color will reset the window back to using the system's default behavior for the caption text color.

Windows 11 (@OSBuild = 22621) or later
    $WMWA_SYSTEMBACKDROP_TYPE (38)
        Specifies the system-drawn backdrop material of a window, including behind the non-client area.
        $iData is a value of type DWM_SYSTEMBACKDROP_TYPE.
            $DWMSBT_AUTO
                The default. Let the Desktop Window Manager (DWM) automatically decide the system-drawn backdrop material for this window. This applies the backdrop material just behind the default Win32 title bar. This behavior attempts to preserve maximum backwards compatibility.
                For this reason, the DWM might also decide to draw no backdrop material at all based on internal heuristics.
                If drawing the backdrop material behind the entire window is required, choose one of the other more specific values of this enum as appropriate.
            $DWMSBT_NONE
                Don't draw any system backdrop.
            $DWMSBT_MAINWINDOW
                Draw the backdrop material effect corresponding to a long-lived window behind the entire window bounds.
                For Windows 11, this corresponds to Mica in its default variant.
                The material effect might change with future Windows releases. For more info about Mica, see Mica.
            $DWMSBT_TRANSIENTWINDOW
                Draw the backdrop material effect corresponding to a transient window behind the entire window bounds.
                For Windows 11, this corresponds to Desktop Acrylic, also known as Background Acrylic, in its brightest variant.
                The material effect might change with future Windows releases. For more info about Desktop Acrylic, see Acrylic.
            $DWMSBT_TABBEDWINDOW
                Draw the backdrop material effect corresponding to a window with a tabbed title bar behind the entire window bounds.
                For Windows 11, this corresponds to Mica in its alternate variant (Mica Alt).
                The material might change with future releases of Windows. For more info about Mica Alt, see Layering with Mica Alt.
$iData The value of the attribute. See $iAttribute for specific values, otherwise True/False.

Return Value

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

Related

_WinAPI_DwmGetWindowAttribute

See Also

Search DwmSetWindowAttribute in MSDN Library.

Example

#include <APIGdiConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.au3>
#include <WindowsSysColorConstants.au3>

Global $g_hGUI, $g_idEdt_Note, $g_sNote, $g_iSet, $g_idChk_DarkMode, $g_idChk_CustomColors

Example() ; Win 10 onwards

Func Example()
    ; Create a GUI with various controls.
    $g_hGUI = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 300, 165)
    _WinAPI_SetThemeAppProperties(0) ; needed to have GUICtrlSetColor() on CheckBox OK

    ; Create a checkbox control.
    $g_idChk_DarkMode = GUICtrlCreateCheckbox("Use Dark mode frame", 10, 10, 125, 25)
    $g_idChk_CustomColors = GUICtrlCreateCheckbox("custom colors on change", 145, 10, 185, 25)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $g_sNote = @CRLF & "Clicking the checkbox allows the window frame " & _
            @CRLF & " for this window to be drawn in dark mode colors" & _
            @CRLF & " when the dark mode system setting is enabled."
    $g_idEdt_Note = GUICtrlCreateEdit($g_sNote, 10, 44, 280, 110, BitOR($ES_CENTER, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))

    ; Display the GUI.
    GUISetState(@SW_SHOW, $g_hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $g_idChk_DarkMode
                If _IsChecked($g_idChk_DarkMode) Then    ;  enable window frame dark mode
                    $g_iSet = _WinAPI_DwmSetWindowAttribute($g_hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True)
                    LetsSeeTheDifference()
                Else                                    ;  disable window frame dark mode
                    $g_iSet = _WinAPI_DwmSetWindowAttribute($g_hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, False)
                    LetsSeeTheDifference()
                EndIf

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($g_hGUI)
EndFunc   ;==>Example

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func LetsSeeTheDifference()
    GUICtrlSetData($g_idEdt_Note, $g_sNote & @CRLF & @CRLF & "DwmSetWindowAttribute: " & ($g_iSet ? 'OK' : 'Failed, see MSDN notes') & @CRLF & '(OSBuild: ' & @OSBuild & ')')
    If Not $g_iSet Then Return
    If _IsChecked($g_idChk_CustomColors) Then
        If _IsChecked($g_idChk_DarkMode) Then
            GUISetBkColor(0x1B1B1B, $g_hGUI)
            GUICtrlSetBkColor($g_idEdt_Note, 0x2B2B2B)
            GUICtrlSetColor($g_idEdt_Note, 0xFBFBFB)
            GUICtrlSetColor($g_idChk_DarkMode, 0xFBFBFB)
            GUICtrlSetColor($g_idChk_CustomColors, 0xFBFBFB)
            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Else
            GUISetBkColor(_WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)), $g_hGUI)
            GUICtrlSetBkColor($g_idEdt_Note, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_BTNFACE)))
            GUICtrlSetColor($g_idEdt_Note, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT)))
            GUICtrlSetColor($g_idChk_DarkMode, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT)))
            GUICtrlSetColor($g_idChk_CustomColors, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT)))
            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        EndIf
    EndIf
    WinActivate("[CLASS:Progman;]") ; To refresh the frame.
    WinActivate($g_hGUI) ;              Only needed for the constant back and forth in this demo.
EndFunc   ;==>LetsSeeTheDifference

Func _WinAPI_DwmSetWindowAttribute_($hWnd, $iAttribute, $iData)
    Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $iAttribute, _
            'dword*', $iData, 'dword', 4)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] Then Return SetError(10, $aCall[0], 0)
    Return 1
EndFunc   ;==>_WinAPI_DwmSetWindowAttribute_