https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e215a088f9ed5e83620d7c4ce949e4f430646d95
commit e215a088f9ed5e83620d7c4ce949e4f430646d95 Author: Jose Carlos Jesus <zecarlos1...@hotmail.com> AuthorDate: Tue Sep 13 16:00:45 2022 +0100 Commit: GitHub <nore...@github.com> CommitDate: Tue Sep 13 18:00:45 2022 +0300 [ATL] Fix window position to fit in screen area (#4512) Clicking "Edit compatibility modes" button in the "Compatibility" tab opens a window centered on the parent window. If we move the parent window to one of the screen edges and then click this button again, the new window will appear off screen. Adjust position of created window, so now it would be completely visible. CORE-17089 Reviewed-by: Mark Jansen <mark.jan...@reactos.org> Reviewed-by: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> --- sdk/lib/atl/atlwin.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/sdk/lib/atl/atlwin.h b/sdk/lib/atl/atlwin.h index 447e06f94b7..b970fe7b173 100644 --- a/sdk/lib/atl/atlwin.h +++ b/sdk/lib/atl/atlwin.h @@ -320,9 +320,37 @@ public: int wndCenterHeight = wndCenterRect.bottom - wndCenterRect.top; int wndWidth = wndRect.right - wndRect.left; int wndHeight = wndRect.bottom - wndRect.top; + int xPos = wndCenterRect.left + ((wndCenterWidth - wndWidth + 1) >> 1); + int yPos = wndCenterRect.top + ((wndCenterHeight - wndHeight + 1) >> 1); + + if (!(::GetWindowLong(hWndCenter, GWL_STYLE) & WS_CHILD)) + { + MONITORINFO mi; + mi.cbSize = sizeof(mi); + HMONITOR hMonitor = MonitorFromWindow(hWndCenter, MONITOR_DEFAULTTOPRIMARY); + GetMonitorInfo(hMonitor, &mi); + + if (xPos + wndWidth > mi.rcWork.right) + { + xPos = mi.rcWork.right - wndWidth; + } + else if (xPos < mi.rcWork.left) + { + xPos = mi.rcWork.left; + } + + if (yPos + wndHeight > mi.rcWork.bottom) + { + yPos = mi.rcWork.bottom - wndHeight; + } + if (yPos < mi.rcWork.top) + { + yPos = mi.rcWork.top; + } + } return ::MoveWindow(m_hWnd, - wndCenterRect.left + ((wndCenterWidth - wndWidth + 1) >> 1), - wndCenterRect.top + ((wndCenterHeight - wndHeight + 1) >> 1), + xPos, + yPos, wndWidth, wndHeight, TRUE); }