Files
2026-08-11 19:41:54 +08:00

46 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Runtime.InteropServices;
namespace LanMountainDesktop.Platform.Windows;
/// <summary>
/// DWM桌面窗口管理器互操作封装。
/// </summary>
public static class WindowsDwmInterop
{
public const int WindowAttributeBorderColor = 34;
public const uint ColorNone = 0xFFFFFFFE;
/// <summary>
/// 移除窗口原生边框颜色Windows 11 22000+)。
/// 失败静默忽略DWM 属性为尽力而为语义)。
/// </summary>
public static void TryDisableWindowBorder(IntPtr windowHandle)
{
if (windowHandle == IntPtr.Zero || !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000))
{
return;
}
try
{
var borderColor = ColorNone;
_ = DwmSetWindowAttribute(
windowHandle,
WindowAttributeBorderColor,
ref borderColor,
sizeof(uint));
}
catch
{
// DWM attributes are best-effort and unavailable on older/unsupported Windows builds.
}
}
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(
IntPtr windowHandle,
int attribute,
ref uint attributeValue,
int attributeSize);
}