[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.jansen@reactos.org>
Reviewed-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
This commit is contained in:
Jose Carlos Jesus 2022-09-13 16:00:45 +01:00 committed by GitHub
parent d7f75a88ea
commit e215a088f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}