From bac71495638a4e82353c32d38da11b8d239d0d24 Mon Sep 17 00:00:00 2001 From: tangge233 Date: Sun, 11 Jan 2026 01:06:41 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=20WindowChrome?= =?UTF-8?q?=20=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utils/OS/KernelInterop.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Utils/OS/KernelInterop.cs b/Utils/OS/KernelInterop.cs index eea525f9..76e50ef9 100644 --- a/Utils/OS/KernelInterop.cs +++ b/Utils/OS/KernelInterop.cs @@ -77,6 +77,12 @@ private struct MEMORYSTATUSEX public ulong ullAvailExtendedVirtual; } + [StructLayout(LayoutKind.Sequential)] + public struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; } + + [DllImport("dwmapi.dll")] + public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); + // ReSharper restore InconsistentNaming, UnusedMember.Local private static void _ThrowLastWin32Error() => throw new Win32Exception(Marshal.GetLastWin32Error()); From 6454be5a8a26c4003ef7604c01a8adc94c165eb3 Mon Sep 17 00:00:00 2001 From: tangge233 Date: Wed, 14 Jan 2026 18:21:18 +0800 Subject: [PATCH 2/4] chore: remove dwmapi to WindowManagerInterop --- Utils/OS/KernelInterop.cs | 6 ------ Utils/OS/WindowManagerInterop.cs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 Utils/OS/WindowManagerInterop.cs diff --git a/Utils/OS/KernelInterop.cs b/Utils/OS/KernelInterop.cs index 76e50ef9..eea525f9 100644 --- a/Utils/OS/KernelInterop.cs +++ b/Utils/OS/KernelInterop.cs @@ -77,12 +77,6 @@ private struct MEMORYSTATUSEX public ulong ullAvailExtendedVirtual; } - [StructLayout(LayoutKind.Sequential)] - public struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; } - - [DllImport("dwmapi.dll")] - public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); - // ReSharper restore InconsistentNaming, UnusedMember.Local private static void _ThrowLastWin32Error() => throw new Win32Exception(Marshal.GetLastWin32Error()); diff --git a/Utils/OS/WindowManagerInterop.cs b/Utils/OS/WindowManagerInterop.cs new file mode 100644 index 00000000..8261f5e6 --- /dev/null +++ b/Utils/OS/WindowManagerInterop.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace PCL.Core.Utils.OS +{ + public partial class WindowManagerInterop + { + [StructLayout(LayoutKind.Sequential)] + public struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; } + + [LibraryImport("dwmapi.dll")] + public static partial int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); + } +} From 74fdb47a009f6e3aa214985a03aa3e8d34555115 Mon Sep 17 00:00:00 2001 From: tangge233 Date: Thu, 15 Jan 2026 09:20:02 +0800 Subject: [PATCH 3/4] feat: add wrap for dwm interop --- Utils/OS/WindowManagerInterop.cs | 38 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Utils/OS/WindowManagerInterop.cs b/Utils/OS/WindowManagerInterop.cs index 8261f5e6..0474d538 100644 --- a/Utils/OS/WindowManagerInterop.cs +++ b/Utils/OS/WindowManagerInterop.cs @@ -1,18 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using PCL.Core.Logging; +using System; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; namespace PCL.Core.Utils.OS { public partial class WindowManagerInterop { [StructLayout(LayoutKind.Sequential)] - public struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; } + private struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; } [LibraryImport("dwmapi.dll")] - public static partial int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); + private static partial int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); + + [LibraryImport("dwmapi.dll")] + private static partial int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] ref bool pfEnabled); + + /// + /// DWM 组合是否可用 + /// + /// + public static bool IsCompositionEnabled() + { + bool enabled = false; + int hResult = DwmIsCompositionEnabled(ref enabled); + if (hResult != 0) + throw new Win32Exception(hResult, "Failed to check DWM status"); + return enabled; + } + + public static void ExtendFrameIntoClientArea(IntPtr hWnd, int margin) + { + MARGINS margins = new() { leftWidth = margin, rightWidth = margin, topHeight = margin, bottomHeight = margin }; + if (IsCompositionEnabled()) + { + int hResult = DwmExtendFrameIntoClientArea(hWnd, ref margins); + if (hResult != 0) throw new Win32Exception(hResult, "Failed to extend frame into client area"); + } + } } } From a60d96b861718d2b52e76babefbeb9a21f4f1d2e Mon Sep 17 00:00:00 2001 From: tangge233 Date: Thu, 15 Jan 2026 09:29:45 +0800 Subject: [PATCH 4/4] chore: replace ref bool with out bool --- Utils/OS/WindowManagerInterop.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Utils/OS/WindowManagerInterop.cs b/Utils/OS/WindowManagerInterop.cs index 0474d538..a45d00ec 100644 --- a/Utils/OS/WindowManagerInterop.cs +++ b/Utils/OS/WindowManagerInterop.cs @@ -14,7 +14,7 @@ private struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeig private static partial int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); [LibraryImport("dwmapi.dll")] - private static partial int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] ref bool pfEnabled); + private static partial int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] out bool pfEnabled); /// /// DWM 组合是否可用 @@ -22,8 +22,7 @@ private struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeig /// public static bool IsCompositionEnabled() { - bool enabled = false; - int hResult = DwmIsCompositionEnabled(ref enabled); + int hResult = DwmIsCompositionEnabled(out var enabled); if (hResult != 0) throw new Win32Exception(hResult, "Failed to check DWM status"); return enabled;