Funktionreferenz


_WinAPI_DwmSetWindowAttribute

Beschreibung anzeigen in

Setzt den Wert des gegebenen Attributs für das Nicht-Client-Rendern welche auf das Fenster angewendet werden sollen

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

Parameter

$hWnd Das Handle des Fensters auf welches die Attribute angewendet werden sollen.
$iAttribute Die Attribute welche auf das Fenster angewendet werden sollen. Dieser Parameter kann einen der folgenden Werte annehmen:
Windows Vista oder höher
    $DWMWA_NCRENDERING_POLICY, $iData kann DWMNCRP_USEWINDOWSTYLE, DWMNCRP_DISABLED, DWMNCRP_ENABLED sein
    $DWMWA_TRANSITIONS_FORCEDISABLED
    $DWMWA_ALLOW_NCPAINT
    $DWMWA_NONCLIENT_RTL_LAYOUT
    $DWMWA_FORCE_ICONIC_REPRESENTATION
    $DWMWA_FLIP3D_POLICY, $iData kann DWMFLIP3D_DEFAULT, DWMFLIP3D_EXCLUDEBELOW, DWMFLIP3D_EXCLUDEABOVE sein

Windows 7 oder höher
    $DWMWA_HAS_ICONIC_BITMAP
    $DWMWA_DISALLOW_PEEK
    $DWMWA_EXCLUDED_FROM_PEEK

Windows 8 oder höher
    $DWMWA_CLOAK
    $DWMWA_FREEZE_REPRESENTATION
    $DWMWA_PASSIVE_UPDATE_MODE

Windows 11 (@OSBuild = 22000) oder höher
    $DWMWA_USE_HOSTBACKDROPBRUSH
    $DWMWA_USE_IMMERSIVE_DARK_MODE (Spezialfall für @OSBuild <= 18985)
    $DWMWA_WINDOW_CORNER_PREFERENCE, $iData kann DWMWCP_DEFAULT, DWMWCP_DONOTROUND, DWMWCP_ROUND, DWMWCP_ROUNDSMALL sein
    $DWMWA_BORDER_COLOR $iData = Colorref
    $DWMWA_CAPTION_COLOR $iData = Colorref
    $DWMWA_TEXT_COLOR $iData = Colorref
    $DWMWA_VISIBLE_FRAME_BORDER_THICKNESS $iData = UINT
$iData Der Wert des Attributs. Siehe $iAttribute für bestimmte Werte, andernfalls Wahr/Falsch.

Rückgabewert

Erfolg: 1.
Fehler: 0 und setzt das @error Flag auf ungleich 0, das @extended Flag kann den HRESULT-Fehlercode enthalten.

Verwandte Funktionen

_WinAPI_DwmGetWindowAttribute

Siehe auch

Suche nach DwmSetWindowAttribute in der MSDN Bibliothek.

Beispiel

#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_