Jump to content

Recommended Posts

Posted (edited)

In several of my projects, I have continued to use (and improve upon) the wonderful _WinAPI_DwmEnableBlurBehindWindow10 script by @scintilla4evr which paved the way for blur options on modern versions of Windows.

I have completely opened the script up with more options and wanted to share the results back with the community for anyone else to enjoy. I have renamed the function to _WinAPI_DwmEnableBlurBehindWindow11 since it is geared more toward Windows 11 options. It may or may not work with Windows 10. Some of the AccentFlags may need to be adjusted with Windows 10. And I've made it possible to change those values when calling the function.

Maybe somebody will make some sort of continuously changing, random color changing blur increasing and decreasing levels of color transparency with it. 😄

I have included inside the function the contents of a function called _percentageOfHex() that was shared to me by @argumentum that takes a percentage 0-100 and returns the Hexadecimal color code for transparency which gets put together with the main color passed to form a COLORREF that can control color transparency levels. I combined that function into _WinAPI_DwmEnableBlurBehindWindow11 to keep things as simple as possible.

Script with Example:

Spoiler
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>

Global $hUser32   = DllOpen('user32.dll')

DllCall($hUser32, "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -4)

Global $DWMWA_COLOR_NONE = 0xFFFFFFFE

Global $WCA_ACCENT_POLICY = 19
Global $ACCENT_DISABLED = 0
Global $ACCENT_ENABLE_GRADIENT = 1
Global $ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
Global $ACCENT_ENABLE_BLURBEHIND = 3
Global $ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
Global $ACCENT_ENABLE_HOSTBACKDROP = 5
Global $ACCENT_INVALID_STATE = 6

Example()

Func Example()
        ; Create a GUI with various controls.
        Local $hGUI = GUICreate("Example", 600, 400)
        GUISetBkColor(0x000000)
        Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

        ; set dark mode for titlebar
        _WinAPI_DwmSetWindowAttribute__($hGUI, 20, 1)

        ; remove window borders
        _WinAPI_DwmSetWindowAttribute__($hGUI, 34, _WinAPI_SwitchColor_mod($DWMWA_COLOR_NONE))

        _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_ACRYLICBLURBEHIND, True, 0x0078D4, 50, 0)
        ;_WinAPI_DwmEnableBlurBehindWindow11($hGUI)

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

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

                EndSwitch
        WEnd

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

Func _WinAPI_DwmSetWindowAttribute__($hwnd, $attribute = 34, $value = 0x00FF00, $valLen = 4)
    Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $attribute, 'dword*', $value, 'dword', $valLen)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] Then Return SetError(10, $aCall[0], 0)
    Return 1
EndFunc   ;==>_WinAPI_DwmSetWindowAttribute__

Func _WinAPI_SwitchColor_mod($iColor)
    If $iColor = $DWMWA_COLOR_NONE Then Return $iColor
    If $iColor = -1 Then Return $iColor
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $BlendColor, $ColorOpacity, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle
;                  $AccentState         - [optional] Enable or disable the blur effect
;                  $IncludeCaption      - [optional] Extend effects to the titlebar
;                  $BlendColor          - [optional] Sets GradientColor
;                  $ColorOpacity        - [optional] Sets blending color opacity value
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $BlendColor, $ColorOpacity, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hWnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $IncludeCaption = True, $BlendColor = "", $ColorOpacity = "", $AccentFlags = 0, $AnimationId = 0)
    If $AccentState And $IncludeCaption Then _WinAPI_DwmEnableBlurBehindWindow($hWnd, 1)
    If Not $AccentState Then _WinAPI_DwmEnableBlurBehindWindow($hWnd, 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($ColorOpacity > 99 ? 100 : ($ColorOpacity < 1 ? 0 : $ColorOpacity)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($BlendColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall($hUser32, "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
    If $AccentState And $IncludeCaption Then _WinAPI_DwmExtendFrameIntoClientArea($hWnd, _WinAPI_CreateMargins(-1, -1, -1, -1))
    If Not $AccentState Then _WinAPI_DwmExtendFrameIntoClientArea($hWnd, _WinAPI_CreateMargins(0, 0, 0, 0))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_WinAPI_DwmEnableBlurBehindWindow11

 

 

Edited by WildByDesign
Updated Sept. 9, 2025
Posted (edited)
Spoiler
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>

DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext", "HWND", "DPI_AWARENESS_CONTEXT" - 4)

Global $DWMWA_COLOR_NONE = 0xFFFFFFFE ;;; https://www.autoitscript.com/forum/topic/213090-_winapi_dwmenableblurbehindwindow-in-windows-11/

Global $WCA_ACCENT_POLICY = 19
Global $ACCENT_DISABLED = 0
Global $ACCENT_ENABLE_GRADIENT = 1
Global $ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
Global $ACCENT_ENABLE_BLURBEHIND = 3
Global $ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
Global $ACCENT_ENABLE_HOSTBACKDROP = 5
Global $ACCENT_INVALID_STATE = 6

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $iInit = 0, $iLeft = 10, $iTop = 10, $hGUI = GUICreate("Example: ACCENT DISABLED", 600, 400)
    GUISetBkColor(0x000000)
    Local $idRadio1 = GUICtrlCreateButton("ACCENT ENABLE &ACRYLICBLURBEHIND - 60%", $iLeft, CtrlAddNextPos($iTop))
    Local $idRadio2 = GUICtrlCreateButton("ACCENT ENABLE &TRANSPARENTGRADIENT - 80%", $iLeft, CtrlAddNextPos($iTop))
    Local $idRadio3 = GUICtrlCreateButton("ACCENT ENABLE &BLURBEHIND", $iLeft, CtrlAddNextPos($iTop))
    Local $idRadio4 = GUICtrlCreateButton("ACCENT &DISABLED", $iLeft, CtrlAddNextPos($iTop))
;~  GUICtrlSetState($idRadio4, $GUI_CHECKED) ; ..had to change to buttons. My main PC is heavily modified and Radio worked just fine,
    Local $idOK = GUICtrlCreateButton("&OK", 310, 370, 85, 25) ;  but not in a "regular" PC  =/
    GUICtrlSetState($idOK, $GUI_FOCUS)

    ; set dark mode for titlebar
    _WinAPI_DwmSetWindowAttribute__($hGUI, 20, 1)

    ; remove window borders
    _WinAPI_DwmSetWindowAttribute__($hGUI, 34, _WinAPI_SwitchColor_mod($DWMWA_COLOR_NONE))

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    WinSetOnTop($hGUI, "", 1)
;~  Send("{ALT}") ; ..to show the accelerator keys

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

            Case $idRadio1
                If Not $iInit Then InitTheGuiBlurBehind($iInit, $hGUI)
                _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_ACRYLICBLURBEHIND, 0x0078D4, 60)
                WinSetTitleAndRefresh($hGUI, "", "Example: ACCENT ENABLE ACRYLICBLURBEHIND - 60%")

            Case $idRadio2
                If Not $iInit Then InitTheGuiBlurBehind($iInit, $hGUI)
                _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_TRANSPARENTGRADIENT, 0x0078D4, 80)
                WinSetTitleAndRefresh($hGUI, "", "Example: ACCENT ENABLE TRANSPARENTGRADIENT - 80%")

            Case $idRadio3
                If Not $iInit Then InitTheGuiBlurBehind($iInit, $hGUI)
                _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_BLURBEHIND)
                WinSetTitleAndRefresh($hGUI, "", "Example: ACCENT ENABLE BLURBEHIND")

            Case $idRadio4
                If $iInit Then
                    ; disable modern blur method
                    _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_DISABLED)
                    ; disable original blur method
                    _WinAPI_DwmEnableBlurBehindWindow($hGUI, 0, 0)
                    ; clear extended frame
                    _WinAPI_DwmExtendFrameIntoClientArea($hGUI, _WinAPI_CreateMargins(0, 0, 0, 0))
                    $iInit = 0
                EndIf
                WinSetTitleAndRefresh($hGUI, "", "Example: ACCENT DISABLED")

        EndSwitch
    WEnd

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

Func WinSetTitleAndRefresh($sTitle, $sText, $sNewTitle, $iCtrl = 0)
    WinSetTitle($sTitle, $sText, $sNewTitle)
    WinActivate("[CLASS:Shell_TrayWnd;]") ; enable or disable this based on Win11 Build number,
    WinActivate($sTitle) ;                     or something. Some times is needed, not always.
    If $iCtrl Then GUICtrlSetState($iCtrl, $GUI_FOCUS)
EndFunc   ;==>WinSetTitleAndRefresh

Func InitTheGuiBlurBehind(ByRef $iInit, $hGUI)
    ; set initial DwmEnableBlurBehindWindow
    Local $hRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRectEx(0, 0, 0, 0))
    _WinAPI_DwmEnableBlurBehindWindow($hGUI, 1, 0, $hRgn)
    If $hRgn Then
        _WinAPI_DeleteObject($hRgn)
    EndIf

    ; extending the frame allows blur on the titlebar as well
    _WinAPI_DwmExtendFrameIntoClientArea($hGUI, _WinAPI_CreateMargins(-1, -1, -1, -1))

    $iInit = 1
EndFunc   ;==>InitTheGuiBlurBehind

Func CtrlAddNextPos(ByRef $iPos, $iAdd = 30)
    Local $iSaved = $iPos
    $iPos += $iAdd
    Return $iSaved
EndFunc   ;==>CtrlAddNextPos

Func _WinAPI_DwmSetWindowAttribute__($hwnd, $attribute = 34, $value = 0x00FF00, $valLen = 4)
    Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hwnd, 'dword', $attribute, 'dword*', $value, 'dword', $valLen)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] Then Return SetError(10, $aCall[0], 0)
    Return 1
EndFunc   ;==>_WinAPI_DwmSetWindowAttribute__

Func _WinAPI_SwitchColor_mod($iColor)
    If $iColor = $DWMWA_COLOR_NONE Then Return $iColor
    If $iColor = -1 Then Return $iColor
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc   ;==>_WinAPI_SwitchColor_mod

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle.
;                  $AccentState         - [optional] Enable or disable the blur effect.
;                  $iBlurColor          - [optional] Sets GradientColor
;                  $iBlurPercent        - [optional] Sets blending color transparency percentage
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hwnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColor = "", $iBlurPercent = 50, $AccentFlags = 0, $AnimationId = 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($iBlurPercent > 99 ? 100 : ($iBlurPercent < 1 ? 0 : $iBlurPercent)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    If $iBlurColor <> "" Then $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($iBlurColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall("user32.dll", "bool", "SetWindowCompositionAttribute", "hwnd", $hwnd, "ptr", DllStructGetPtr($tAttrData))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_WinAPI_DwmEnableBlurBehindWindow11

...the 5 seconds sampling was, insufficient :lol: 

Liked it. Thanks for sharing :) 

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)
2 hours ago, argumentum said:

Liked it. Thanks for sharing :)

You're welcome. And thank you for the sharing your example as well with the buttons. Your example makes more sense for being able to play around with the example. I've never been very good with examples.

I was working on another example earlier today using a slider to automatically change the color transparency in real-time and it's working well. So I think what I will do is combine my slider example with your example and should make for a good example in the end.

Also, I was thinking of adding an input box (likely a color picker too) to change color. And with that, maybe a "Random Color" button as well. :)

Edited by WildByDesign
Posted

I really wanted to make an Example script to showcase everything that this function can do, such as changing blend color, random color button, slider for color transparency percentage, etc. However, I just don't have enough time to do it right now and my GUI skills are still lacking.

I did put together a functional slider example to change the color transparency percentage in real-time which is quit neat. You would have to change the color in the script though for different colors.

Example with color transparency slider:

Spoiler
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <GuiSlider.au3>
#include <WindowsConstants.au3>
#include <SliderConstants.au3>

#include <WinAPISysWin.au3>

DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -4)
Opt("GUIOnEventMode", 1)

Global $hGUI, $BlurColorIntensitySlider, $iBlurColPercentLast
Global $iBlurColorSet = 0x0078D4
Global $iBlurColPercent = 20

Global $DWMWA_COLOR_NONE = 0xFFFFFFFE

Global $WCA_ACCENT_POLICY = 19
Global $ACCENT_DISABLED = 0
Global $ACCENT_ENABLE_GRADIENT = 1
Global $ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
Global $ACCENT_ENABLE_BLURBEHIND = 3
Global $ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
Global $ACCENT_ENABLE_HOSTBACKDROP = 5
Global $ACCENT_INVALID_STATE = 6

Example()

Func Example()
        ; Create a GUI with various controls.
        Local $hGUI = GUICreate("ACCENT_ENABLE_ACRYLICBLURBEHIND - 20%", 600, 400)
        GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
        GUISetBkColor(0x000000)

        $BlurColorIntensitySlider = GUICtrlCreateSlider(50, 50, 240, 50, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
        ;GUICtrlSetOnEvent(-1, "_SliderFunction")
        $hWndTT = _GUICtrlSlider_GetToolTips($BlurColorIntensitySlider)
        _GUICtrlSlider_SetToolTips($BlurColorIntensitySlider, $hWndTT)
        GUICtrlSetBkColor($BlurColorIntensitySlider, 0x00000000)
        GUICtrlSetLimit(-1, 100, 0)
        GUICtrlSetData($BlurColorIntensitySlider, 20)

        ; set dark mode for titlebar
        _WinAPI_DwmSetWindowAttribute__($hGUI, 20, 1)

        ; remove window borders
        _WinAPI_DwmSetWindowAttribute__($hGUI, 34, _WinAPI_SwitchColor_mod($DWMWA_COLOR_NONE))
        
        ; set initial DwmEnableBlurBehindWindow
        Local $hRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRectEx(0, 0, 0, 0))
        _WinAPI_DwmEnableBlurBehindWindow($hGUI, 1, 0, $hRgn)
        If $hRgn Then
            _WinAPI_DeleteObject($hRgn)
        EndIf

        _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColorSet, $iBlurColPercent, 0)
        WinSetTitle($hGUI, "", "ACCENT_ENABLE_ACRYLICBLURBEHIND - 20%")

        ; extending the frame allows blur on the titlebar as well
        _WinAPI_DwmExtendFrameIntoClientArea($hGUI, _WinAPI_CreateMargins(-1, -1, -1, -1))

        ; kill dots
        GUICtrlSendMsg( $BlurColorIntensitySlider, $WM_CHANGEUISTATE, 65537, 0)

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

        ; Just idle around
        While 1
            Sleep(100)

            $iBlurColPercent = GUICtrlRead($BlurColorIntensitySlider)
            If $iBlurColPercent<>$iBlurColPercentLast Then
                _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColorSet, $iBlurColPercent, 0)
                $iBlurColPercentLast = $iBlurColPercent
                WinSetTitle($hGUI, "", "ACCENT_ENABLE_TRANSPARENTGRADIENT - " & $iBlurColPercent & "%")
            EndIf
        WEnd

EndFunc   ;==>Example

Func _SliderFunction()
    ;Local $iBlurColPercent = GUICtrlRead($BlurColorIntensitySlider)
    ;ConsoleWrite("$iSliderRead: " & $iBlurColPercent & @CRLF)
    Sleep(200)
    ;_WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_ENABLE_TRANSPARENTGRADIENT, 0x00ff00, $iBlurColPercent, 0)
    ; disable modern blur method
    _WinAPI_DwmEnableBlurBehindWindow11($hGUI, $ACCENT_DISABLED)
    ; disable original blur method
    _WinAPI_DwmEnableBlurBehindWindow($hGUI, 0, 0)
    _WinAPI_UpdateWindow($hGUI)
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            Exit
    EndSelect
EndFunc

Func _WinAPI_DwmSetWindowAttribute__($hwnd, $attribute = 34, $value = 0x00FF00, $valLen = 4)
    Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $attribute, 'dword*', $value, 'dword', $valLen)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] Then Return SetError(10, $aCall[0], 0)
    Return 1
EndFunc   ;==>_WinAPI_DwmSetWindowAttribute__

Func _WinAPI_SwitchColor_mod($iColor)
    If $iColor = $DWMWA_COLOR_NONE Then Return $iColor
    If $iColor = -1 Then Return $iColor
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle.
;                  $AccentState         - [optional] Enable or disable the blur effect.
;                  $iBlurColor          - [optional] Sets GradientColor
;                  $iBlurPercent        - [optional] Sets blending color transparency percentage
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hWnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColor = "", $iBlurPercent = 50, $AccentFlags = 0, $AnimationId = 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($iBlurPercent > 99 ? 100 : ($iBlurPercent < 1 ? 0 : $iBlurPercent)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    If $iBlurColor <> "" Then $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($iBlurColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall("user32.dll", "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc

 

 

  • 2 weeks later...
Posted
21 minutes ago, mlibre2 said:

Hi, I just came across this topic. My script has this functionality, I realized it doesn't work in w11. I think I'll try your version.

I was just checking out your myLogin program this morning.

Are you applying the blur fullscreen?

Does your work on win10?

Posted

I just tested an example of a fullscreen GUI on Windows 11 and it seems to do the blur nicely.

Example:

Spoiler
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

Global $WCA_ACCENT_POLICY = 19
Global $ACCENT_DISABLED = 0
Global $ACCENT_ENABLE_GRADIENT = 1
Global $ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
Global $ACCENT_ENABLE_BLURBEHIND = 3
Global $ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
Global $ACCENT_ENABLE_HOSTBACKDROP = 5
Global $ACCENT_INVALID_STATE = 6

HotKeySet("{Esc}", "_exit")

; Create main window (fullscreen)
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x000000, $hGUI)
_WinAPI_DwmEnableBlurBehindWindow11($hGUI)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
    Sleep(50)
WEnd

Func _exit()
    Exit
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle.
;                  $AccentState         - [optional] Enable or disable the blur effect.
;                  $iBlurColor          - [optional] Sets GradientColor
;                  $iBlurPercent        - [optional] Sets blending color transparency percentage
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hWnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColor = "", $iBlurPercent = 50, $AccentFlags = 0, $AnimationId = 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($iBlurPercent > 99 ? 100 : ($iBlurPercent < 1 ? 0 : $iBlurPercent)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    If $iBlurColor <> "" Then $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($iBlurColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall("user32.dll", "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc

 

 

Posted
2 hours ago, WildByDesign said:

I was just checking out your myLogin program this morning.

Are you applying the blur fullscreen?

Does your work on win10?

Yes, where it doesn't run well is on w7 and 11. I'm also about to try it on a virtual machine in w8. I guess it should work. We'll see.

 

59 minutes ago, WildByDesign said:

I just tested an example of a fullscreen GUI on Windows 11 and it seems to do the blur nicely.

Example:

  Reveal hidden contents
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

Global $WCA_ACCENT_POLICY = 19
Global $ACCENT_DISABLED = 0
Global $ACCENT_ENABLE_GRADIENT = 1
Global $ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
Global $ACCENT_ENABLE_BLURBEHIND = 3
Global $ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
Global $ACCENT_ENABLE_HOSTBACKDROP = 5
Global $ACCENT_INVALID_STATE = 6

HotKeySet("{Esc}", "_exit")

; Create main window (fullscreen)
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x000000, $hGUI)
_WinAPI_DwmEnableBlurBehindWindow11($hGUI)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
    Sleep(50)
WEnd

Func _exit()
    Exit
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle.
;                  $AccentState         - [optional] Enable or disable the blur effect.
;                  $iBlurColor          - [optional] Sets GradientColor
;                  $iBlurPercent        - [optional] Sets blending color transparency percentage
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $iBlurColor, $iBlurPercent, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hWnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $iBlurColor = "", $iBlurPercent = 50, $AccentFlags = 0, $AnimationId = 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($iBlurPercent > 99 ? 100 : ($iBlurPercent < 1 ? 0 : $iBlurPercent)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    If $iBlurColor <> "" Then $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($iBlurColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall("user32.dll", "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc

 

 

 :thumbsup: Well, I haven't tested it yet. When I get back to the office, I'll check. My computer hasn't migrated to that operating system yet.

myLogin 🛡️

Posted

@WildByDesign Which version of w11 worked for you? I tried installing a virtual machine with the version Home 23H2 Build 22631.5472, and $ACCENT_ENABLE_ACRYLICBLURBEHIND made the background completely black. I'll try it in 24H2. Another thing: $ACCENT_ENABLE_BLURBEHIND only works with w10.

myLogin 🛡️

Posted

I use 24H2 on my main machine. I just tested with ACCENT_ENABLE_GRADIENT, ACCENT_ENABLE_TRANSPARENTGRADIENT, ACCENT_ENABLE_BLURBEHIND and ACCENT_ENABLE_ACRYLICBLURBEHIND and they all work for me. One thing that I do know for sure is that the color blending with ACCENT_ENABLE_ACRYLICBLURBEHIND does not seem to work on Windows 10.

Did you test with me full screen blur example above?

I may try and test your program to see if I can get it to work. Does your au3 script accept the command line args or does it have to be compiled?

Posted (edited)
2 hours ago, mlibre2 said:

I tried installing a virtual machine with...

Then that's that. A VM will not be the same as a HW one.
The remote desktop that connects to it is the "viewer". Not quite a hardware monitor on the PC.
Not sure if it can be done personally. It should I guess. But in my VMs I didn't even try.

 

Edit: Well, I did. And it worked too :) 

Enable rounded corners: 
reg add HKLM\SOFTWARE\Microsoft\Windows\Dwm /v ForceEffectMode /t REG_DWORD /d 2 /f

Disable the effects (restore defaults): 
reg delete HKLM\SOFTWARE\Microsoft\Windows\Dwm /v ForceEffectMode /f

funny enough, all the settings were as expected but, nothing.
Added this "ForceEffectMode" that was for "round corners" in a remote desktop, and that did it.

image.png.74e498a48609ab8251c5c666092103ba.png

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
1 hour ago, argumentum said:

Then that's that. A VM will not be the same as a HW one.
The remote desktop that connects to it is the "viewer". Not quite a hardware monitor on the PC.

This is probably the case.

I would add _WinAPI_DwmIsCompositionEnabled to the myLogin script to ensure that composition is available and enabled.

The hardware has to be capable (possibly the VM may not) plus Transparency has to be enabled in the Settings app in Win11.

Posted
On 9/7/2025 at 10:19 PM, WildByDesign said:

I would add _WinAPI_DwmIsCompositionEnabled to the myLogin script to ensure that composition is available and enabled.

I'm testing the function, and it always returns "true," even if the effect is disabled. Perhaps add this filter to the function to check for compatibility...

; Windows 11
   If @OSBuild >= 22000 Then
      $regKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
      $regValue = "EnableTransparency"

      If RegRead($regKey, $regValue) <> 1 Then
         WinSetTrans($hGUI, "", $g_iTransparencyGUI)
         Return False
      EndIf
   EndIf

 

myLogin 🛡️

Posted
18 minutes ago, mlibre2 said:

disabled. Perhaps add this filter to the function to check for compatibility...

This is a great idea. Although probably makes more sense to have it in a users’ script as opposed to having it in the main function.

Posted

I just updated the _WinAPI_DwmEnableBlurBehindWindow11 function. I was able to make it so that it behaves just like the original AutoIt _WinAPI_DwmEnableBlurBehindWindow function used to behave prior to Windows 10 which is to extend the blur to the titlebar of the window. I made it default since that is how the original function used to behave before it broke on Windows 10. Titlebar blur can be disabled. I also opened up the entire SetWindowCompositionAttribute API so that you can experiment with any part of it.

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinAPI_DwmEnableBlurBehindWindow11
; Description ...: Enables Aero-like blurred background in Windows 11.
; Syntax ........: _WinAPI_DwmEnableBlurBehindWindow11($hWnd[, $AccentState, $BlendColor, $ColorOpacity, $AccentFlags, $AnimationId])
; Parameters ....: $hWnd                - Window handle
;                  $AccentState         - [optional] Enable or disable the blur effect
;                  $IncludeCaption      - [optional] Extend effects to the titlebar
;                  $BlendColor          - [optional] Sets GradientColor
;                  $ColorOpacity        - [optional] Sets blending color opacity value
;                  $AccentFlags         - [optional] Sets AccentFlags value
;                  $AnimationId         - [optional] Sets AnimationId value
; Return values .: 1 on success, 0 otherwise. Call _WinAPI_GetLastError on failure for more information.
; Author ........: scintilla4evr
; Modified ......: WildByDesign - added $AccentState, $BlendColor, $ColorOpacity, $AccentFlags and $AnimationId
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
;    ACCENT_DISABLED = 0
;    ACCENT_ENABLE_GRADIENT = 1
;    ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
;    ACCENT_ENABLE_BLURBEHIND = 3
;    ACCENT_ENABLE_ACRYLICBLURBEHIND = 4
;    ACCENT_ENABLE_HOSTBACKDROP = 5
;    ACCENT_INVALID_STATE = 6
; ===============================================================================================================================
Func _WinAPI_DwmEnableBlurBehindWindow11($hWnd, $AccentState = $ACCENT_ENABLE_ACRYLICBLURBEHIND, $IncludeCaption = True, $BlendColor = "", $ColorOpacity = "", $AccentFlags = 0, $AnimationId = 0)
    If $AccentState And $IncludeCaption Then _WinAPI_DwmEnableBlurBehindWindow($hWnd, 1)
    If Not $AccentState Then _WinAPI_DwmEnableBlurBehindWindow($hWnd, 0)
    Local $tAccentPolicy = DllStructCreate("int AccentState; int AccentFlags; int GradientColor; int AnimationId")
    Local $tAttrData = DllStructCreate("dword Attribute; ptr DataBuffer; ulong Size")
    $tAccentPolicy.AccentState = $AccentState
    If $AccentState = $ACCENT_ENABLE_TRANSPARENTGRADIENT And $AccentFlags = 0 Then $AccentFlags = 2
    $tAccentPolicy.AccentFlags = $AccentFlags
    Local $iVal = Int($ColorOpacity > 99 ? 100 : ($ColorOpacity < 1 ? 0 : $ColorOpacity)) ; no more than 100% or less than 0%
    Local $sTransparencyHex = Hex(Ceiling(($iVal * 100) * (2.55 * 100) / (100 * 100)), 2)
    $tAccentPolicy.GradientColor = '0x' & $sTransparencyHex & Hex(_WinAPI_SwitchColor($BlendColor), 6)
    $tAccentPolicy.AnimationId = $AnimationId
    $tAttrData.Attribute = $WCA_ACCENT_POLICY
    $tAttrData.DataBuffer = DllStructGetPtr($tAccentPolicy)
    $tAttrData.Size = DllStructGetSize($tAccentPolicy)

    Local $aResult = DllCall($hUser32, "bool", "SetWindowCompositionAttribute", "hwnd", $hWnd, "ptr", DllStructGetPtr($tAttrData))
    If $AccentState And $IncludeCaption Then _WinAPI_DwmExtendFrameIntoClientArea($hWnd, _WinAPI_CreateMargins(-1, -1, -1, -1))
    If Not $AccentState Then _WinAPI_DwmExtendFrameIntoClientArea($hWnd, _WinAPI_CreateMargins(0, 0, 0, 0))
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_WinAPI_DwmEnableBlurBehindWindow11

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...