Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Utils/OS/WindowManagerInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using PCL.Core.Logging;
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace PCL.Core.Utils.OS
{
public partial class WindowManagerInterop
{
[StructLayout(LayoutKind.Sequential)]
private struct MARGINS { public int leftWidth, rightWidth, topHeight, bottomHeight; }

[LibraryImport("dwmapi.dll")]
private static partial int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);

[LibraryImport("dwmapi.dll")]
private static partial int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] out bool pfEnabled);

/// <summary>
/// DWM 组合是否可用
/// </summary>
/// <returns></returns>
public static bool IsCompositionEnabled()
{
int hResult = DwmIsCompositionEnabled(out var 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");
}
}
}
}
Loading