diff --git a/ShareX.HelpersLib/DWMManager.cs b/ShareX.HelpersLib/DWMManager.cs index e017a4e07..00b6c5292 100644 --- a/ShareX.HelpersLib/DWMManager.cs +++ b/ShareX.HelpersLib/DWMManager.cs @@ -53,7 +53,7 @@ public void ChangeComposition(bool enable) { try { - NativeMethods.DwmEnableComposition(enable ? CompositionAction.DWM_EC_ENABLECOMPOSITION : CompositionAction.DWM_EC_DISABLECOMPOSITION); + NativeMethods.DwmEnableComposition(enable ? DWM_EC.DWM_EC_ENABLECOMPOSITION : DWM_EC.DWM_EC_DISABLECOMPOSITION); } catch (Exception e) { diff --git a/ShareX.HelpersLib/Native/NativeEnums.cs b/ShareX.HelpersLib/Native/NativeEnums.cs index fed0db5d4..e08b21ebe 100644 --- a/ShareX.HelpersLib/Native/NativeEnums.cs +++ b/ShareX.HelpersLib/Native/NativeEnums.cs @@ -184,23 +184,6 @@ public enum TaskBarEdge Right } - [Flags] - public enum DWM_BB - { - Enable = 1, - BlurRegion = 2, - TransitionMaximized = 4 - } - - [Flags] - public enum DwmNCRenderingPolicy - { - UseWindowStyle, - Disabled, - Enabled, - Last - } - public enum SystemMetric { /// @@ -1987,83 +1970,63 @@ public enum BitmapCompressionMode : uint BI_PNG = 5 } - [Flags] - public enum CompositionAction : uint + public enum DWMWINDOWATTRIBUTE : uint + { + DWMWA_NCRENDERING_ENABLED = 1, + DWMWA_NCRENDERING_POLICY, + DWMWA_TRANSITIONS_FORCEDISABLED, + DWMWA_ALLOW_NCPAINT, + DWMWA_CAPTION_BUTTON_BOUNDS, + DWMWA_NONCLIENT_RTL_LAYOUT, + DWMWA_FORCE_ICONIC_REPRESENTATION, + DWMWA_FLIP3D_POLICY, + DWMWA_EXTENDED_FRAME_BOUNDS, + DWMWA_HAS_ICONIC_BITMAP, + DWMWA_DISALLOW_PEEK, + DWMWA_EXCLUDED_FROM_PEEK, + DWMWA_CLOAK, + DWMWA_CLOAKED, + DWMWA_FREEZE_REPRESENTATION, + DWMWA_PASSIVE_UPDATE_MODE, + DWMWA_USE_HOSTBACKDROPBRUSH, + DWMWA_USE_IMMERSIVE_DARK_MODE = 20, + DWMWA_WINDOW_CORNER_PREFERENCE = 33, + DWMWA_BORDER_COLOR, + DWMWA_CAPTION_COLOR, + DWMWA_TEXT_COLOR, + DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, + DWMWA_SYSTEMBACKDROP_TYPE, + DWMWA_LAST + } + + public enum DWMNCRENDERINGPOLICY + { + DWMNCRP_USEWINDOWSTYLE, + DWMNCRP_DISABLED, + DWMNCRP_ENABLED, + DWMNCRP_LAST + } + + public enum DWM_WINDOW_CORNER_PREFERENCE + { + DWMWCP_DEFAULT, + DWMWCP_DONOTROUND, + DWMWCP_ROUND, + DWMWCP_ROUNDSMALL + } + + public enum DWM_EC : uint { DWM_EC_DISABLECOMPOSITION = 0, DWM_EC_ENABLECOMPOSITION = 1 } - public enum DwmWindowAttribute : uint + [Flags] + public enum DWM_BB { - /// - /// Use with DwmGetWindowAttribute. Discovers whether non-client rendering is enabled. The retrieved value is of type BOOL. TRUE if non-client rendering is enabled; otherwise, FALSE. - /// - DWMWA_NCRENDERING_ENABLED = 1, - /// - /// Use with DwmSetWindowAttribute. Sets the non-client rendering policy. The pvAttribute parameter points to a value from the DWMNCRENDERINGPOLICY enumeration. - /// - DWMWA_NCRENDERING_POLICY, - /// - /// Use with DwmSetWindowAttribute. Enables or forcibly disables DWM transitions. The pvAttribute parameter points to a value of TRUE to disable transitions or FALSE to enable transitions. - /// - DWMWA_TRANSITIONS_FORCEDISABLED, - /// - /// Use with DwmSetWindowAttribute. Enables content rendered in the non-client area to be visible on the frame drawn by DWM. The pvAttribute parameter points to a value of TRUE to enable content rendered in the non-client area to be visible on the frame; otherwise, it points to FALSE. - /// - DWMWA_ALLOW_NCPAINT, - /// - /// Use with DwmGetWindowAttribute. Retrieves the bounds of the caption button area in the window-relative space. The retrieved value is of type RECT. - /// - DWMWA_CAPTION_BUTTON_BOUNDS, - /// - /// Use with DwmSetWindowAttribute. Specifies whether non-client content is right-to-left (RTL) mirrored. The pvAttribute parameter points to a value of TRUE if the non-client content is right-to-left (RTL) mirrored; otherwise, it points to FALSE. - /// - DWMWA_NONCLIENT_RTL_LAYOUT, - /// - /// Use with DwmSetWindowAttribute. 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. This value 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. The pvAttribute parameter points to a value of TRUE to require a iconic thumbnail or peek representation; otherwise, it points to FALSE. - /// - DWMWA_FORCE_ICONIC_REPRESENTATION, - /// - /// Use with DwmSetWindowAttribute. Sets how Flip3D treats the window. The pvAttribute parameter points to a value from the DWMFLIP3DWINDOWPOLICY enumeration. - /// - DWMWA_FLIP3D_POLICY, - /// - /// Use with DwmGetWindowAttribute. Retrieves the extended frame bounds rectangle in screen space. The retrieved value is of type RECT. - /// - DWMWA_EXTENDED_FRAME_BOUNDS, - /// - /// Use with DwmSetWindowAttribute. The window will provide a bitmap for use by DWM as an iconic thumbnail or peek representation (a static bitmap) for the window. 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. The pvAttribute parameter points to a value of TRUE to inform DWM that the window will provide an iconic thumbnail or peek representation; otherwise, it points to FALSE. - /// - DWMWA_HAS_ICONIC_BITMAP, - /// - /// Use with DwmSetWindowAttribute. Do not show peek preview for the window. 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). The pvAttribute parameter points to a value of TRUE to prevent peek functionality or FALSE to allow it. - /// - DWMWA_DISALLOW_PEEK, - /// - /// Use with DwmSetWindowAttribute. Prevents a window from fading to a glass sheet when peek is invoked. The pvAttribute parameter points to a value of TRUE to prevent the window from fading during another window's peek or FALSE for normal behavior. - /// - DWMWA_EXCLUDED_FROM_PEEK, - /// - /// Use with DwmSetWindowAttribute. Cloaks the window such that it is not visible to the user. The window is still composed by DWM. - /// - DWMWA_CLOAK, - /// - /// Use with DwmGetWindowAttribute. - /// - DWMWA_CLOAKED, - /// - /// Use with DwmSetWindowAttribute. 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, - /// - /// The maximum recognized DWMWINDOWATTRIBUTE value, used for validation purposes. - /// - DWMWA_LAST, - // Undocumented, available since October 2018 update (build 17763) - DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19, - // Windows 10 20H1 changed the value of the constant - DWMWA_USE_IMMERSIVE_DARK_MODE = 20 + DWM_BB_ENABLE = 1, + DWM_BB_BLURREGION = 2, + DWM_BB_TRANSITIONONMAXIMIZED = 4 } public enum InputType : int diff --git a/ShareX.HelpersLib/Native/NativeMethods.cs b/ShareX.HelpersLib/Native/NativeMethods.cs index e43548064..aa51d39b1 100644 --- a/ShareX.HelpersLib/Native/NativeMethods.cs +++ b/ShareX.HelpersLib/Native/NativeMethods.cs @@ -432,7 +432,7 @@ public static extern bool CreateProcess(string lpApplicationName, string lpComma public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind); [DllImport("dwmapi.dll", PreserveSig = false)] - public static extern void DwmEnableComposition(CompositionAction uCompositionAction); + public static extern void DwmEnableComposition(DWM_EC uCompositionAction); [DllImport("dwmapi.dll")] public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins); diff --git a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs index e85cce2b9..49346aa95 100644 --- a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs +++ b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs @@ -228,45 +228,40 @@ public static bool IsDWMEnabled() public static bool GetExtendedFrameBounds(IntPtr handle, out Rectangle rectangle) { - int result = DwmGetWindowAttribute(handle, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out RECT rect, Marshal.SizeOf(typeof(RECT))); + int result = DwmGetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out RECT rect, Marshal.SizeOf(typeof(RECT))); rectangle = rect; return result == 0; } public static bool GetNCRenderingEnabled(IntPtr handle) { - int result = DwmGetWindowAttribute(handle, (int)DwmWindowAttribute.DWMWA_NCRENDERING_ENABLED, out bool enabled, sizeof(bool)); + int result = DwmGetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_ENABLED, out bool enabled, sizeof(bool)); return result == 0 && enabled; } - public static void SetNCRenderingPolicy(IntPtr handle, DwmNCRenderingPolicy renderingPolicy) + public static void SetNCRenderingPolicy(IntPtr handle, DWMNCRENDERINGPOLICY renderingPolicy) { - int renderPolicy = (int)renderingPolicy; - DwmSetWindowAttribute(handle, (int)DwmWindowAttribute.DWMWA_NCRENDERING_POLICY, ref renderPolicy, sizeof(int)); + int attrValue = (int)renderingPolicy; + DwmSetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, ref attrValue, sizeof(int)); } public static bool UseImmersiveDarkMode(IntPtr handle, bool enabled) { - if (Helpers.IsWindows10OrGreater(17763)) + if (Helpers.IsWindows10OrGreater(18985)) { - DwmWindowAttribute attribute; - - if (Helpers.IsWindows10OrGreater(18985)) - { - attribute = DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE; - } - else - { - attribute = DwmWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1; - } - int useImmersiveDarkMode = enabled ? 1 : 0; - return DwmSetWindowAttribute(handle, (int)attribute, ref useImmersiveDarkMode, sizeof(int)) == 0; + return DwmSetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref useImmersiveDarkMode, sizeof(int)) == 0; } return false; } + public static void SetWindowCornerPreference(IntPtr handle, DWM_WINDOW_CORNER_PREFERENCE cornerPreference) + { + int attrValue = (int)cornerPreference; + DwmSetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref attrValue, sizeof(int)); + } + public static Rectangle GetWindowRect(IntPtr handle) { GetWindowRect(handle, out RECT rect); @@ -379,7 +374,7 @@ public static bool IsWindowCloaked(IntPtr handle) { if (IsDWMEnabled()) { - int result = DwmGetWindowAttribute(handle, (int)DwmWindowAttribute.DWMWA_CLOAKED, out int cloaked, sizeof(int)); + int result = DwmGetWindowAttribute(handle, (int)DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out int cloaked, sizeof(int)); return result == 0 && cloaked != 0; } diff --git a/ShareX/Tools/PinToScreen/PinToScreenForm.cs b/ShareX/Tools/PinToScreen/PinToScreenForm.cs index 009d11058..05a781e5e 100644 --- a/ShareX/Tools/PinToScreen/PinToScreenForm.cs +++ b/ShareX/Tools/PinToScreen/PinToScreenForm.cs @@ -332,7 +332,12 @@ protected override void WndProc(ref Message m) { if (Options.Shadow && m.Msg == (int)WindowsMessages.NCPAINT && isDWMEnabled) { - NativeMethods.SetNCRenderingPolicy(Handle, DwmNCRenderingPolicy.Enabled); + NativeMethods.SetNCRenderingPolicy(Handle, DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED); + + if (Helpers.IsWindows11OrGreater()) + { + NativeMethods.SetWindowCornerPreference(Handle, DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_DONOTROUND); + } MARGINS margins = new MARGINS() {