基于WebView2实现的Win11桌面框架,利用插件自定义
Moli
2026-05-03 2fd6e68025d4b987cfde52b8402038ca34116876
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
 
namespace Moli.Desktop.Interop;
 
/// <summary>Fallback strategy that keeps the wallpaper window at the bottom of normal Z-order.</summary>
public sealed class BottomDesktopLayerStrategy : IDesktopLayerStrategy
{
    private readonly IDiagnosticsService _diagnostics;
 
    public BottomDesktopLayerStrategy(IDiagnosticsService diagnostics)
    {
        _diagnostics = diagnostics;
    }
 
    public string Name => "BottomDesktopLayer";
 
    public bool IsSupported() => true;
 
    public bool TryAttachWallpaperWindow(IntPtr hwnd, MonitorInfo monitor, out string? error)
    {
        error = null;
        if (!NativeMethods.SetWindowPos(
            hwnd,
            NativeMethods.HwndBottom,
            (int)monitor.Bounds.X,
            (int)monitor.Bounds.Y,
            (int)monitor.Bounds.Width,
            (int)monitor.Bounds.Height,
            NativeMethods.SwpNoActivate | NativeMethods.SwpShowWindow))
        {
            error = $"SetWindowPos failed with {NativeMethods.GetLastError()}";
            _diagnostics.Record(
                DiagnosticSeverity.Warning,
                DiagnosticCodes.DesktopLayerAttachFailed,
                "Failed to place window at bottom desktop layer.",
                new Dictionary<string, string> { ["reason"] = error });
            return false;
        }
 
        _diagnostics.Record(
            DiagnosticSeverity.Info,
            DiagnosticCodes.DesktopLayerStrategySelected,
            "Desktop layer strategy selected.",
            new Dictionary<string, string> { ["strategy"] = Name });
        return true;
    }
}