From f345f3f814841bf23bc83041dcfdbb8633c0a3f8 Mon Sep 17 00:00:00 2001 From: RaiKoHoff Date: Wed, 17 Jun 2020 16:23:31 +0200 Subject: [PATCH] + fix: DPI Aware relative positioning of position managed dialog boxes --- src/Dialogs.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index ee6ed8909..79fd3d836 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -3896,6 +3896,8 @@ void GetDlgPos(HWND hDlg, LPINT xDlg, LPINT yDlg) { if (!hDlg) { return; } + DPI_T const dpi = Scintilla_GetWindowDPI(hDlg); + RECT rcDlg; GetWindowRect(hDlg, &rcDlg); @@ -3903,9 +3905,15 @@ void GetDlgPos(HWND hDlg, LPINT xDlg, LPINT yDlg) RECT rcParent; GetWindowRect(hParent, &rcParent); - // return positions relative to parent window - if (xDlg) { *xDlg = (rcDlg.left - rcParent.left); } - if (yDlg) { *yDlg = (rcDlg.top - rcParent.top); } + // return positions relative to parent window (normalized DPI) + if (xDlg) + { + *xDlg = MulDiv((rcDlg.left - rcParent.left), USER_DEFAULT_SCREEN_DPI, (dpi.x ? dpi.x : USER_DEFAULT_SCREEN_DPI)); + } + if (yDlg) + { + *yDlg = MulDiv((rcDlg.top - rcParent.top), USER_DEFAULT_SCREEN_DPI, (dpi.y ? dpi.y : USER_DEFAULT_SCREEN_DPI)); + } } @@ -3917,6 +3925,8 @@ void SetDlgPos(HWND hDlg, int xDlg, int yDlg) { if (!hDlg) { return; } + DPI_T const dpi = Scintilla_GetWindowDPI(hDlg); + RECT rcDlg; GetWindowRect(hDlg, &rcDlg); @@ -3936,9 +3946,9 @@ void SetDlgPos(HWND hDlg, int xDlg, int yDlg) int const xMax = (mi.rcWork.right) - (rcDlg.right - rcDlg.left); int const yMax = (mi.rcWork.bottom) - (rcDlg.bottom - rcDlg.top); - // desired positions relative to parent window - int const x = rcParent.left + xDlg; - int const y = rcParent.top + yDlg; + // desired positions relative to parent window (normalized DPI) + int const x = rcParent.left + MulDiv(xDlg, dpi.x, USER_DEFAULT_SCREEN_DPI); + int const y = rcParent.top + MulDiv(yDlg, dpi.y, USER_DEFAULT_SCREEN_DPI); SetWindowPos(hDlg, NULL, clampi(x, xMin, xMax), clampi(y, yMin, yMax), 0, 0, SWP_NOZORDER | SWP_NOSIZE); }