fix: draw in software over remote desktop so the window has no black area

This commit is contained in:
2026-08-28 06:56:00 +00:00
parent cc579d794e
commit 9dcd9055d9
+20 -1
View File
@@ -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;