基于WebView2实现的Win11桌面框架,利用插件自定义
chunhualin1
2026-08-14 09d4e2f1a1bc206c80d8d3287d070c70ec7fd63d
src/Moli.Desktop/Interop/Win32InteropService.cs
@@ -190,15 +190,25 @@
        var styleFlag = unchecked((uint)flag);
        var currentStyle = unchecked((uint)current);
        var updated = enabled ? currentStyle | styleFlag : currentStyle & ~styleFlag;
        NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GwlExStyle, new IntPtr(updated));
        var error = NativeMethods.GetLastError();
        if (error != 0)
        if (updated == currentStyle)
        {
            _diagnostics.Record(
                DiagnosticSeverity.Warning,
                DiagnosticCodes.Win32InteropFailed,
                $"{operation} failed.",
                new Dictionary<string, string> { ["hwnd"] = hwnd.ToString("X"), ["error"] = error.ToString() });
            return;
        }
        NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GwlExStyle, new IntPtr(unchecked((int)updated)));
        // Extended-style changes (especially WS_EX_TRANSPARENT) do not reliably update hit-testing
        // until the frame is refreshed. Without this, clearing click-through in edit/safe-input
        // mode can leave the window visually present but permanently unclickable.
        if (!NativeMethods.SetWindowPos(
            hwnd,
            IntPtr.Zero,
            0,
            0,
            0,
            0,
            NativeMethods.SwpNoMove | NativeMethods.SwpNoSize | NativeMethods.SwpNoZOrder | NativeMethods.SwpNoActivate | NativeMethods.SwpFrameChanged))
        {
            RecordWin32Failure($"{operation}.SetWindowPos", hwnd);
        }
    }