Skip to content

Commit 941c030

Browse files
committed
Fix position error on windows 10
In windows 10, there is a invisible borders. When window's position is set to (0, 0), there will be some gap between screen left border and game window left border. This commit fix the issue with solution provided in: https://stackoverflow.com/a/34143777/1277762
1 parent 65555c1 commit 941c030

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

d2gl/src/win32.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "helpers.h"
2323
#include "modules/hd_cursor.h"
2424
#include "option/menu.h"
25+
#include "dwmapi.h"
2526

2627
#include <detours/detours.h>
2728

@@ -361,12 +362,33 @@ void setWindowRect()
361362
RECT wr_test = { 0 };
362363
AdjustWindowRect(&wr_test, App.window.style, FALSE);
363364

365+
AdjustWindowRect(&wr, App.window.style, FALSE);
366+
367+
// apply the shift
364368
wr.left -= wr_test.left;
365369
wr.right -= wr_test.left;
366370
wr.top -= wr_test.top;
367371
wr.bottom -= wr_test.top;
368372

369-
AdjustWindowRect(&wr, App.window.style, FALSE);
373+
// show window first to get GetWindowRect works
374+
SetWindowPos_Og(App.hwnd, HWND_NOTOPMOST, wr.left, wr.top, (wr.right - wr.left), (wr.bottom - wr.top), SWP_SHOWWINDOW);
375+
376+
// Get the invisible borders
377+
RECT fr = { 0 };
378+
DwmGetWindowAttribute(App.hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &fr, sizeof(fr));
379+
380+
RECT border;
381+
border.left = fr.left - wr.left;
382+
border.top = fr.top - wr.top;
383+
border.right = wr.right - fr.right;
384+
border.bottom = wr.bottom - fr.bottom;
385+
386+
// apply the border
387+
wr.left -= border.left;
388+
wr.top -= border.top;
389+
wr.right += border.right;
390+
wr.bottom += border.bottom;
391+
370392
SetWindowPos_Og(App.hwnd, HWND_NOTOPMOST, wr.left, wr.top, (wr.right - wr.left), (wr.bottom - wr.top), SWP_SHOWWINDOW);
371393
trace_log("Switched to windowed mode: %d x %d", App.window.size.x, App.window.size.y);
372394
} else {
@@ -490,4 +512,4 @@ RTL_OSVERSIONINFOW getOSVersion()
490512
return info;
491513
}
492514

493-
}
515+
}

0 commit comments

Comments
 (0)