基于WebView2实现的Win11桌面框架,利用插件自定义
Moli
2026-05-05 4df6165fa93c7caeea86385312415e312de4d11f
src/Moli.Desktop/Interop/Win32InteropService.cs
@@ -79,6 +79,7 @@
    public void RestoreTopLevelWindow(IntPtr hwnd)
    {
        RestoreTopLevelStyle(hwnd);
        NativeMethods.SetParent(hwnd, IntPtr.Zero);
        var error = NativeMethods.GetLastError();
        if (error != 0)
@@ -88,6 +89,18 @@
                DiagnosticCodes.Win32InteropFailed,
                "RestoreTopLevelWindow failed.",
                new Dictionary<string, string> { ["hwnd"] = hwnd.ToString("X"), ["error"] = error.ToString() });
        }
        if (!NativeMethods.SetWindowPos(
            hwnd,
            IntPtr.Zero,
            0,
            0,
            0,
            0,
            NativeMethods.SwpNoMove | NativeMethods.SwpNoSize | NativeMethods.SwpNoZOrder | NativeMethods.SwpNoActivate | NativeMethods.SwpFrameChanged))
        {
            RecordWin32Failure("RestoreTopLevelWindow.SetWindowPos", hwnd);
        }
    }
@@ -186,4 +199,11 @@
    {
        return new RectD(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
    }
    private static void RestoreTopLevelStyle(IntPtr hwnd)
    {
        var current = unchecked((uint)NativeMethods.GetWindowLongPtr(hwnd, NativeMethods.GwlStyle).ToInt64());
        var updated = (current | NativeMethods.WsPopup | NativeMethods.WsVisible) & ~NativeMethods.WsChild;
        NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GwlStyle, new IntPtr(unchecked((int)updated)));
    }
}