From cf40cded1708bb303be4a404b7aceddd196e1d46 Mon Sep 17 00:00:00 2001
From: Moli <13026959681@163.com>
Date: 星期三, 29 七月 2026 20:58:14 +0800
Subject: [PATCH] v1.0
---
src/Moli.Desktop/Interop/Win32InteropService.cs | 39 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 38 insertions(+), 1 deletions(-)
diff --git a/src/Moli.Desktop/Interop/Win32InteropService.cs b/src/Moli.Desktop/Interop/Win32InteropService.cs
index ad6a2af..6bed968 100644
--- a/src/Moli.Desktop/Interop/Win32InteropService.cs
+++ b/src/Moli.Desktop/Interop/Win32InteropService.cs
@@ -45,6 +45,9 @@
}
public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor)
+ => MoveToDesktopLayer(hwnd, mode, monitor.Bounds);
+
+ public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, RectD bounds)
{
var candidates = mode == DesktopLayerMode.WorkerW
? _strategies.OrderBy(strategy => strategy is WorkerWDesktopLayerStrategy ? 0 : 1)
@@ -57,7 +60,7 @@
continue;
}
- if (strategy.TryAttachWallpaperWindow(hwnd, monitor, out var error))
+ if (strategy.TryAttachDesktopWindow(hwnd, bounds, out var error))
{
return;
}
@@ -71,6 +74,33 @@
["strategy"] = strategy.Name,
["reason"] = error ?? "Unknown"
});
+ }
+ }
+
+ public void RestoreTopLevelWindow(IntPtr hwnd)
+ {
+ RestoreTopLevelStyle(hwnd);
+ NativeMethods.SetParent(hwnd, IntPtr.Zero);
+ var error = NativeMethods.GetLastError();
+ if (error != 0)
+ {
+ _diagnostics.Record(
+ DiagnosticSeverity.Warning,
+ 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);
}
}
@@ -169,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)));
+ }
}
--
Gitblit v1.9.1