From 9dcd9055d9aca188ddb9a290da4d8921ce9a25e8 Mon Sep 17 00:00:00 2001 From: kua-agent Date: Fri, 28 Aug 2026 06:56:00 +0000 Subject: [PATCH] fix: draw in software over remote desktop so the window has no black area --- App.xaml.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/App.xaml.cs b/App.xaml.cs index 0e6545a..02887b1 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.IO; using System.IO.Compression; @@ -68,8 +68,27 @@ namespace MmdPdf // Startup // ============================================================ + // Windows reports whether we are being viewed over a remote desktop. In that case WPF's + // hardware compositing hands the session a surface it never repaints when the desktop is + // resized, which leaves the part of the window outside the original size drawn as flat + // black. Drawing in software costs nothing at this size and keeps the whole window painted. + [DllImport("user32.dll")] + private static extern int GetSystemMetrics(int index); + private const int SM_REMOTESESSION = 0x1000; + + private static void UseSoftwareRenderingOnRemoteDesktops() + { + try + { + if (GetSystemMetrics(SM_REMOTESESSION) != 0) + RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; + } + catch { /* never let a rendering hint stop the application starting */ } + } + protected override void OnStartup(StartupEventArgs e) { + UseSoftwareRenderingOnRemoteDesktops(); StartupTrace.Mark("App.OnStartup entered"); DispatcherUnhandledException += OnDispatcherException; AppDomain.CurrentDomain.UnhandledException += OnDomainException;