Skip to content

Commit b1fece5

Browse files
committed
Update index.md
1 parent f513d76 commit b1fece5

File tree

1 file changed

+2
-4
lines changed
  • Website/blog/2026-03-04-deep-dive-fixing-dpi-scaling-issues-for-embedded-processes

1 file changed

+2
-4
lines changed

Website/blog/2026-03-04-deep-dive-fixing-dpi-scaling-issues-for-embedded-processes/index.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,14 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e)
264264

265265
// VisualTreeHelper.GetDpi returns DpiScaleX/Y as a ratio (1.0 = 96 DPI, 1.5 = 144 DPI).
266266
var dpi = System.Windows.Media.VisualTreeHelper.GetDpi(this);
267-
WindowHost.Height = (int)((ActualHeight - 20) * dpi.DpiScaleY);
268-
WindowHost.Width = (int)((ActualWidth - 20) * dpi.DpiScaleX);
267+
WindowHost.Height = (int)(ActualHeight * dpi.DpiScaleY);
268+
WindowHost.Width = (int)(ActualWidth * dpi.DpiScaleX);
269269

270270
Connect().ConfigureAwait(false);
271271
_initialized = true;
272272
}
273273
```
274274

275-
The `-20` offset compensates for a layout quirk introduced by the Dragablz tab control (see [pull request #2678](https://github.com/BornToBeRoot/NETworkManager/pull/2678)).
276-
277275
## Summary
278276

279277
When you embed a foreign process window via `SetParent`, Windows never forwards DPI change notifications across process boundaries. For console host processes (PowerShell, cmd) use the Windows Console API (`AttachConsole` + `SetCurrentConsoleFontEx`) to rescale fonts directly; for GUI processes (PuTTY) send `WM_DPICHANGED` (0x02E0) explicitly with the new DPI packed into `wParam`. In both cases, apply an initial DPI correction after `SetParent` by comparing `GetDpiForWindow` before and after embedding, and set the `WindowsFormsHost` initial size in physical pixels using `VisualTreeHelper.GetDpi`.

0 commit comments

Comments
 (0)