Merge pull request 'fix: no black area around the window over a remote desktop' (#7) from fix/mmd-pdf-remote-desktop-black-area-20260828 into main
This commit was merged in pull request #7.
This commit is contained in:
+20
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user