// This Source Code is partially based on reverse engineering of the Windows Operating System,
// and is intended for use on Windows systems only.
// This Source Code is partially based on the source code provided by the .NET Foundation.
//
// NOTE:
// I split unmanaged code stuff into the NativeMethods library.
// If you have suggestions for the code below, please submit your changes there.
// https://github.com/lepoco/nativemethods
//
// Windows Kits\10\Include\10.0.22000.0\um\dwmapi.h
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
#pragma warning disable CA1060 // Move pinvokes to native methods class
using WPFluent.Interop.WinDef;
using System.Runtime.InteropServices;
namespace WPFluent.Interop;
///
/// Desktop Window Manager (DWM).
///
internal static class Dwmapi
{
///
/// Extends the window frame into the client area.
///
/// The handle to the window in which the frame will be extended into the client area.
///
/// A pointer to a MARGINS structure that describes the margins to use when extending the frame into the client
/// area.
///
[DllImport(Libraries.Dwmapi, PreserveSig = false)]
public static extern void DwmExtendFrameIntoClientArea([In] IntPtr hWnd, [In] ref UxTheme.MARGINS pMarInset);
///
/// The feature is not included in the Microsoft documentation. Reads Desktop Window Manager (DWM) color
/// information.
///
/// A pointer to a reference value that will hold the color information.
[DllImport(Libraries.Dwmapi, EntryPoint = "#127", PreserveSig = false, CharSet = CharSet.Unicode)]
public static extern void DwmGetColorizationParameters([Out] out DWMCOLORIZATIONPARAMS dwParameters);
///
/// Retrieves the current composition timing information for a specified window.
///
/// The handle to the window for which the composition timing information should be retrieved.
///
/// A pointer to a structure that, when this function returns successfully, receives
/// the current composition timing information for the window.
///
[DllImport(Libraries.Dwmapi)]
public static extern void DwmGetCompositionTimingInfo([In] IntPtr hWnd, [In] ref DWM_TIMING_INFO pTimingInfo);
///
/// Retrieves the current value of a specified Desktop Window Manager (DWM) attribute applied to a window. For
/// programming guidance, and code examples, see Controlling non-client region rendering.
///
/// The handle to the window from which the attribute value is to be retrieved.
///
/// A flag describing which value to retrieve, specified as a value of the
/// enumeration.
///
///
/// A pointer to a value which, when this function returns successfully, receives the current value of the
/// attribute. The type of the retrieved value depends on the value of the dwAttribute parameter.
///
/// The size, in bytes, of the attribute value being received via the pvAttribute parameter.
/// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi)]
public static extern int DwmGetWindowAttribute(
[In] IntPtr hWnd,
[In] DWMWINDOWATTRIBUTE dwAttributeToGet,
[In] ref int pvAttributeValue,
[In] int cbAttribute);
///
/// Retrieves the current value of a specified Desktop Window Manager (DWM) attribute applied to a window. For
/// programming guidance, and code examples, see Controlling non-client region rendering.
///
/// The handle to the window from which the attribute value is to be retrieved.
///
/// A flag describing which value to retrieve, specified as a value of the
/// enumeration.
///
///
/// A pointer to a value which, when this function returns successfully, receives the current value of the
/// attribute. The type of the retrieved value depends on the value of the dwAttribute parameter.
///
/// The size, in bytes, of the attribute value being received via the pvAttribute parameter.
/// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi)]
public static extern int DwmGetWindowAttribute(
[In] IntPtr hWnd,
[In] int dwAttributeToGet,
[In] ref int pvAttributeValue,
[In] int cbAttribute);
///
/// Called by an application to indicate that all previously provided iconic bitmaps from a window, both thumbnails
/// and peek representations, should be refreshed.
///
///
/// A handle to the window or tab whose bitmaps are being invalidated through this call. This window must belong to
/// the calling process.
///
[DllImport(Libraries.Dwmapi, PreserveSig = false)]
public static extern void DwmInvalidateIconicBitmaps([In] IntPtr hWnd);
///
/// Obtains a value that indicates whether Desktop Window Manager (DWM) composition is enabled.
///
///
/// A pointer to a value that, when this function returns successfully, receives TRUE if DWM composition is enabled;
/// otherwise, FALSE.
///
/// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi, BestFitMapping = false)]
public static extern int DwmIsCompositionEnabled([Out] out int pfEnabled);
///
/// Sets a static, iconic bitmap to display a live preview (also known as a Peek preview) of a window or tab. The
/// taskbar can use this bitmap to show a full-sized preview of a window or tab.
///
/// A handle to the window. This window must belong to the calling process.
/// A handle to the bitmap to represent the window that hwnd specifies.
///
/// The offset of a tab window's client region (the content area inside the client window frame) from the host
/// window's frame. This offset enables the tab window's contents to be drawn correctly in a live preview when it is
/// drawn without its frame.
///
/// The display options for the live preview.
[DllImport(Libraries.Dwmapi, PreserveSig = false)]
public static extern int DwmSetIconicLivePreviewBitmap(
[In] IntPtr hWnd,
[In] IntPtr hbmp,
[In, Optional] POINT pptClient,
[In] DWM_SIT dwSITFlags);
///
/// Sets a static, iconic bitmap on a window or tab to use as a thumbnail representation. The taskbar can use this
/// bitmap as a thumbnail switch target for the window or tab.
///
/// A handle to the window or tab. This window must belong to the calling process.
/// A handle to the bitmap to represent the window that hwnd specifies.
/// The display options for the thumbnail.
[DllImport(Libraries.Dwmapi, PreserveSig = false)]
public static extern void DwmSetIconicThumbnail([In] IntPtr hWnd, [In] IntPtr hbmp, [In] DWM_SIT dwSITFlags);
///
/// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
///
/// The handle to the window for which the attribute value is to be set.
/// A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.
/// A pointer to an object containing the attribute value to set.
/// The size, in bytes, of the attribute value being set via the pvAttribute parameter.
/// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi)]
public static extern int DwmSetWindowAttribute(
[In] IntPtr hWnd,
[In] int dwAttribute,
[In] ref int pvAttribute,
[In] int cbAttribute);
///
/// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
///
/// The handle to the window for which the attribute value is to be set.
/// A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.
/// A pointer to an object containing the attribute value to set.
/// The size, in bytes, of the attribute value being set via the pvAttribute parameter.
/// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi)]
public static extern int DwmSetWindowAttribute(
[In] IntPtr hWnd,
[In] DWMWINDOWATTRIBUTE dwAttribute,
[In] ref int pvAttribute,
[In] int cbAttribute);
///
/// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
///
/// The handle to the window for which the attribute value is to be set.
/// A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.
/// A pointer to an object containing the attribute value to set.
/// The size, in bytes, of the attribute value being set via the pvAttribute parameter.
/// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
[DllImport(Libraries.Dwmapi)]
public static extern int DwmSetWindowAttribute(
[In] IntPtr hWnd,
[In] DWMWINDOWATTRIBUTE dwAttribute,
[In] ref uint pvAttribute,
[In] int cbAttribute);
///
/// Cloaked flags describing why a window is cloaked.
///
public enum DWM_CLOAKED
{
DWM_CLOAKED_APP = 0x00000001,
DWM_CLOAKED_SHELL = 0x00000002,
DWM_CLOAKED_INHERITED = 0x00000004,
}
///
/// GT_*
///
public enum GESTURE_TYPE
{
GT_PEN_TAP = 0,
GT_PEN_DOUBLETAP = 1,
GT_PEN_RIGHTTAP = 2,
GT_PEN_PRESSANDHOLD = 3,
GT_PEN_PRESSANDHOLDABORT = 4,
GT_TOUCH_TAP = 5,
GT_TOUCH_DOUBLETAP = 6,
GT_TOUCH_RIGHTTAP = 7,
GT_TOUCH_PRESSANDHOLD = 8,
GT_TOUCH_PRESSANDHOLDABORT = 9,
GT_TOUCH_PRESSANDTAP = 10,
}
///
/// DWMTWR_* Tab window requirements.
///
public enum DWM_TAB_WINDOW_REQUIREMENTS
{
///
/// This result means the window meets all requirements requested.
///
DWMTWR_NONE = 0x0000,
///
/// In some configurations, admin/user setting or mode of the system means that windows won't be tabbed This
/// requirement says that the system/mode must implement tabbing and if it does not nothing can be done to
/// change this.
///
DWMTWR_IMPLEMENTED_BY_SYSTEM = 0x0001,
///
/// The window has an owner or parent so is ineligible for tabbing.
///
DWMTWR_WINDOW_RELATIONSHIP = 0x0002,
///
/// The window has styles that make it ineligible for tabbing. To be eligible windows must:
/// Have the WS_OVERLAPPEDWINDOW (WS_CAPTION, WS_THICKFRAME, etc.) styles set. Not have
/// WS_POPUP, WS_CHILD or WS_DLGFRAME set. Not have WS_EX_TOPMOST or WS_EX_TOOLWINDOW set.
///
DWMTWR_WINDOW_STYLES = 0x0004,
// The window has a region (set using SetWindowRgn) making it ineligible.
DWMTWR_WINDOW_REGION = 0x0008,
///
/// The window is ineligible due to its Dwm configuration. It must not extended its client area into the title
/// bar using DwmExtendFrameIntoClientArea It must not have DWMWA_NCRENDERING_POLICY set to DWMNCRP_ENABLED
///
DWMTWR_WINDOW_DWM_ATTRIBUTES = 0x0010,
///
/// The window is ineligible due to it's margins, most likely due to custom handling in WM_NCCALCSIZE. The
/// window must use the default window margins for the non-client area.
///
DWMTWR_WINDOW_MARGINS = 0x0020,
///
/// The window has been explicitly opted out by setting DWMWA_TABBING_ENABLED to FALSE.
///
DWMTWR_TABBING_ENABLED = 0x0040,
///
/// The user has configured this application to not participate in tabbing.
///
DWMTWR_USER_POLICY = 0x0080,
///
/// The group policy has configured this application to not participate in tabbing.
///
DWMTWR_GROUP_POLICY = 0x0100,
///
/// This is set if app compat has blocked tabs for this window. Can be overridden per window by setting
/// DWMWA_TABBING_ENABLED to TRUE. That does not override any other tabbing requirements.
///
DWMTWR_APP_COMPAT = 0x0200,
}
///
/// Flags used by the DwmSetWindowAttribute function to specify the rounded corner preference for a window.
///
[Flags]
public enum DWM_WINDOW_CORNER_PREFERENCE
{
DEFAULT = 0,
DONOTROUND = 1,
ROUND = 2,
ROUNDSMALL = 3,
}
///
/// Backdrop types.
///
[Flags]
public enum DWMSBT : uint
{
///
/// Automatically selects backdrop effect.
///
DWMSBT_AUTO = 0,
///
/// Turns off the backdrop effect.
///
DWMSBT_DISABLE = 1,
///
/// Sets Mica effect with generated wallpaper tint.
///
DWMSBT_MAINWINDOW = 2,
///
/// Sets acrlic effect.
///
DWMSBT_TRANSIENTWINDOW = 3,
///
/// Sets blurred wallpaper effect, like Mica without tint.
///
DWMSBT_TABBEDWINDOW = 4,
}
///
/// Non-client rendering policy attribute values
///
public enum DWMNCRENDERINGPOLICY
{
///
/// Enable/disable non-client rendering based on window style
///
DWMNCRP_USEWINDOWSTYLE,
///
/// Disabled non-client rendering; window style is ignored
///
DWMNCRP_DISABLED,
///
/// Enabled non-client rendering; window style is ignored
///
DWMNCRP_ENABLED,
///
/// Sentinel value.
///
DWMNCRP_LAST,
}
///
/// Values designating how Flip3D treats a given window.
///
public enum DWMFLIP3DWINDOWPOLICY
{
///
/// Hide or include the window in Flip3D based on window style and visibility.
///
DWMFLIP3D_DEFAULT,
///
/// Display the window under Flip3D and disabled.
///
DWMFLIP3D_EXCLUDEBELOW,
///
/// Display the window above Flip3D and enabled.
///
DWMFLIP3D_EXCLUDEABOVE,
///
/// Sentinel value.
///
DWMFLIP3D_LAST,
}
///
/// Options used by the DwmGetWindowAttribute and DwmSetWindowAttribute functions.
///
[Flags]
public enum DWMWINDOWATTRIBUTE
{
///
/// Is non-client rendering enabled/disabled
///
DWMWA_NCRENDERING_ENABLED = 1,
///
/// DWMNCRENDERINGPOLICY - Non-client rendering policy
///
DWMWA_NCRENDERING_POLICY = 2,
///
/// Potentially enable/forcibly disable transitions
///
DWMWA_TRANSITIONS_FORCEDISABLED = 3,
///
/// Enables content rendered in the non-client area to be visible on the frame drawn by DWM.
///
DWMWA_ALLOW_NCPAINT = 4,
///
/// Retrieves the bounds of the caption button area in the window-relative space.
///
DWMWA_CAPTION_BUTTON_BOUNDS = 5,
///
/// Is non-client content RTL mirrored
///
DWMWA_NONCLIENT_RTL_LAYOUT = 6,
///
/// 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.
///
DWMWA_FORCE_ICONIC_REPRESENTATION = 7,
///
/// Designates how Flip3D will treat the window.
///
DWMWA_FLIP3D_POLICY = 8,
///
/// Gets the extended frame bounds rectangle in screen space
///
DWMWA_EXTENDED_FRAME_BOUNDS = 9,
///
/// Indicates an available bitmap when there is no better thumbnail representation.
///
DWMWA_HAS_ICONIC_BITMAP = 10,
///
/// Don't invoke Peek on the window.
///
DWMWA_DISALLOW_PEEK = 11,
///
/// LivePreview exclusion information
///
DWMWA_EXCLUDED_FROM_PEEK = 12,
///
/// Cloaks the window such that it is not visible to the user.
///
DWMWA_CLOAK = 13,
///
/// If the window is cloaked, provides one of the following values explaining why.
///
DWMWA_CLOAKED = 14,
///
/// 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_FREEZE_REPRESENTATION = 15,
///
/// BOOL, Updates the window only when desktop composition runs for other reasons
///
DWMWA_PASSIVE_UPDATE_MODE = 16,
///
/// BOOL, Allows the use of host backdrop brushes for the window.
///
DWMWA_USE_HOSTBACKDROPBRUSH = 17,
///
/// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
///
DMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19,
///
/// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
///
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
///
/// Controls the policy that rounds top-level window corners. Windows 11 and above.
///
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
///
/// The color of the thin border around a top-level window.
///
DWMWA_BORDER_COLOR = 34,
///
/// The color of the caption. Windows 11 and above.
///
DWMWA_CAPTION_COLOR = 35,
///
/// The color of the caption text. Windows 11 and above.
///
DWMWA_TEXT_COLOR = 36,
///
/// Width of the visible border around a thick frame window. Windows 11 and above.
///
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37,
///
/// Allows to enter a value from 0 to 4 deciding on the imposed backdrop effect.
///
DWMWA_SYSTEMBACKDROP_TYPE = 38,
///
/// Indicates whether the window should use the Mica effect. Windows 11 and above.
///
DWMWA_MICA_EFFECT = 1029,
}
///
/// Represents the current DWM color accent settings.
///
[StructLayout(LayoutKind.Sequential)]
public struct DWMCOLORIZATIONPARAMS
{
///
/// ColorizationColor
///
public uint clrColor;
///
/// ColorizationAfterglow.
///
public uint clrAfterGlow;
///
/// ColorizationColorBalance.
///
public uint nIntensity;
///
/// ColorizationAfterglowBalance.
///
public uint clrAfterGlowBalance;
///
/// ColorizationBlurBalance.
///
public uint clrBlurBalance;
///
/// ColorizationGlassReflectionIntensity.
///
public uint clrGlassReflectionIntensity;
///
/// ColorizationOpaqueBlend.
///
public bool fOpaque;
}
///
/// Defines a data type used by the Desktop Window Manager (DWM) APIs. It represents a generic ratio and is used for
/// different purposes and units even within a single API.
///
[StructLayout(LayoutKind.Sequential)]
public struct UNSIGNED_RATIO
{
///
/// The ratio numerator.
///
public uint uiNumerator;
///
/// The ratio denominator.
///
public uint uiDenominator;
}
///
/// Specifies the input operations for which visual feedback should be provided. This enumeration is used by the
/// DwmShowContact function.
///
public enum DWM_SHOWCONTACT
{
DWMSC_DOWN,
DWMSC_UP,
DWMSC_DRAG,
DWMSC_HOLD,
DWMSC_PENBARREL,
DWMSC_NONE,
DWMSC_ALL,
}
///
/// Flags used by the DwmSetPresentParameters function to specify the frame sampling type.
///
public enum DWM_SOURCE_FRAME_SAMPLING
{
///
/// Use the first source frame that includes the first refresh of the output frame
///
DWM_SOURCE_FRAME_SAMPLING_POINT,
///
/// Use the source frame that includes the most refreshes of out the output frame in case of multiple source
/// frames with the same coverage the last will be used
///
DWM_SOURCE_FRAME_SAMPLING_COVERAGE,
///
/// Sentinel value.
///
DWM_SOURCE_FRAME_SAMPLING_LAST,
}
///
/// Specifies Desktop Window Manager (DWM) composition timing information. Used by the function.
///
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DWM_TIMING_INFO
{
public int cbSize;
public UNSIGNED_RATIO rateRefresh;
public ulong qpcRefreshPeriod;
public UNSIGNED_RATIO rateCompose;
public ulong qpcVBlank;
public ulong cRefresh;
public uint cDXRefresh;
public ulong qpcCompose;
public ulong cFrame;
public uint cDXPresent;
public ulong cRefreshFrame;
public ulong cFrameSubmitted;
public uint cDXPresentSubmitted;
public ulong cFrameConfirmed;
public uint cDXPresentConfirmed;
public ulong cRefreshConfirmed;
public uint cDXRefreshConfirmed;
public ulong cFramesLate;
public uint cFramesOutstanding;
public ulong cFrameDisplayed;
public ulong qpcFrameDisplayed;
public ulong cRefreshFrameDisplayed;
public ulong cFrameComplete;
public ulong qpcFrameComplete;
public ulong cFramePending;
public ulong qpcFramePending;
public ulong cFramesDisplayed;
public ulong cFramesComplete;
public ulong cFramesPending;
public ulong cFramesAvailable;
public ulong cFramesDropped;
public ulong cFramesMissed;
public ulong cRefreshNextDisplayed;
public ulong cRefreshNextPresented;
public ulong cRefreshesDisplayed;
public ulong cRefreshesPresented;
public ulong cRefreshStarted;
public ulong cPixelsReceived;
public ulong cPixelsDrawn;
public ulong cBuffersEmpty;
}
///
/// SIT flags.
///
public enum DWM_SIT
{
///
/// None.
///
NONE,
///
/// Displays a frame around the provided bitmap.
///
DISPLAYFRAME = 1,
}
}
#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter
#pragma warning restore CA1060 // Move pinvokes to native methods class