From e8bde380942d356e64292b01a437310dd4ac50bf Mon Sep 17 00:00:00 2001 From: fedejeanne Date: Thu, 16 Oct 2025 14:41:53 +0200 Subject: [PATCH] [Windows] Place new windows near top-left corner of their parents #2608 If there is a parent present at the moment when the window is created then set the initial position of the new window to be near the top-left corner of its parent. This avoids unnecessary DPI change events in case that the new window stays in the same monitor were its parent is. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/2608 --- .../win32/org/eclipse/swt/widgets/Control.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index bcfd141fe0d..e9d76e272aa 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -668,12 +668,25 @@ Control computeTabRoot () { void createHandle () { long hwndParent = widgetParent (); + + int x=OS.CW_USEDEFAULT; + int y=0; + + // Set it to be near the top-left corner of the parent shell by default + if (hwndParent != 0) { + RECT rect = new RECT(); + OS.GetWindowRect(hwndParent, rect); + + x = rect.left + 100; + y = rect.top + 100; + } + handle = OS.CreateWindowEx ( widgetExtStyle (), windowClass (), null, widgetStyle (), - OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0, + x, y, OS.CW_USEDEFAULT, 0, hwndParent, 0, OS.GetModuleHandle (null),