On Windows 11 do not round corners

This commit is contained in:
Jaex 2023-10-08 17:07:14 +03:00
parent e170d70f45
commit 9283e0bb87
5 changed files with 73 additions and 110 deletions

View file

@ -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)
{

View file

@ -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
{
/// <summary>
@ -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
{
/// <summary>
/// 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.
/// </summary>
DWMWA_NCRENDERING_ENABLED = 1,
/// <summary>
/// Use with DwmSetWindowAttribute. Sets the non-client rendering policy. The pvAttribute parameter points to a value from the DWMNCRENDERINGPOLICY enumeration.
/// </summary>
DWMWA_NCRENDERING_POLICY,
/// <summary>
/// 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.
/// </summary>
DWMWA_TRANSITIONS_FORCEDISABLED,
/// <summary>
/// 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.
/// </summary>
DWMWA_ALLOW_NCPAINT,
/// <summary>
/// Use with DwmGetWindowAttribute. Retrieves the bounds of the caption button area in the window-relative space. The retrieved value is of type RECT.
/// </summary>
DWMWA_CAPTION_BUTTON_BOUNDS,
/// <summary>
/// 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.
/// </summary>
DWMWA_NONCLIENT_RTL_LAYOUT,
/// <summary>
/// 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.
/// </summary>
DWMWA_FORCE_ICONIC_REPRESENTATION,
/// <summary>
/// Use with DwmSetWindowAttribute. Sets how Flip3D treats the window. The pvAttribute parameter points to a value from the DWMFLIP3DWINDOWPOLICY enumeration.
/// </summary>
DWMWA_FLIP3D_POLICY,
/// <summary>
/// Use with DwmGetWindowAttribute. Retrieves the extended frame bounds rectangle in screen space. The retrieved value is of type RECT.
/// </summary>
DWMWA_EXTENDED_FRAME_BOUNDS,
/// <summary>
/// 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.
/// </summary>
DWMWA_HAS_ICONIC_BITMAP,
/// <summary>
/// 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.
/// </summary>
DWMWA_DISALLOW_PEEK,
/// <summary>
/// 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.
/// </summary>
DWMWA_EXCLUDED_FROM_PEEK,
/// <summary>
/// Use with DwmSetWindowAttribute. Cloaks the window such that it is not visible to the user. The window is still composed by DWM.
/// </summary>
DWMWA_CLOAK,
/// <summary>
/// Use with DwmGetWindowAttribute.
/// </summary>
DWMWA_CLOAKED,
/// <summary>
/// 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.
/// </summary>
DWMWA_FREEZE_REPRESENTATION,
/// <summary>
/// The maximum recognized DWMWINDOWATTRIBUTE value, used for validation purposes.
/// </summary>
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

View file

@ -432,7 +432,7 @@ public static partial class NativeMethods
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);

View file

@ -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;
}

View file

@ -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()
{