Skip to content

Commit 905fdb9

Browse files
committed
[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 #2608
1 parent 6347ad3 commit 905fdb9

File tree

1 file changed

+14
-1
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+14
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,25 @@ Control computeTabRoot () {
668668

669669
void createHandle () {
670670
long hwndParent = widgetParent ();
671+
672+
int x=OS.CW_USEDEFAULT;
673+
int y=0;
674+
675+
// Set it to be near the top-left corner of the parent shell by default
676+
if (hwndParent != 0) {
677+
RECT rect = new RECT();
678+
OS.GetWindowRect(hwndParent, rect);
679+
680+
x = rect.left + 100;
681+
y = rect.top + 100;
682+
}
683+
671684
handle = OS.CreateWindowEx (
672685
widgetExtStyle (),
673686
windowClass (),
674687
null,
675688
widgetStyle (),
676-
OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
689+
x, y, OS.CW_USEDEFAULT, 0,
677690
hwndParent,
678691
0,
679692
OS.GetModuleHandle (null),

0 commit comments

Comments
 (0)