docs对于 MINMAXINFO
的 ptMaxSize
和 ptMaxPosition
组件说:
For top-level windows, this value is based on (...) the primary monitor.
陈峰 elaborates :
If the specified size is greater than or equal to the size of the primary monitor, then the
ptMaxSize
is adjusted to include the difference in size between the primary monitor and the actual monitor. (...) But ifptMaxSize
does not completely cover the monitor, then its value is used as-is.
因此,如果我想填写 MINMAXINFO
以便最大化到非主监视器的窗口,在具有不同分辨率/方向的主监视器的设置中,填充工作区域,但没有如果碰巧在同一台显示器上,则重叠任务栏...我如何才能可靠地做到这一点?
ISTM,一旦我获得了窗口打开的监视器的工作区尺寸并计算了所需的窗口最大尺寸:
- 如果主显示器的宽度与工作区域相同或更宽,我可以不考虑宽度
- 否则,如果窗口比它所在的显示器宽,我可以减去显示器宽度之间的差异
- 否则,我无法描述我想要的宽度
...高度也一样。
如果我对它进行编码,我确实得到了所描述的行为......除了在显示器具有相同分辨率但方向不同的情况下,调整似乎没有得到应用。
这一切看起来令人难以置信的复杂和奇怪。我错过或误解了什么吗?实际上我应该做一些简单可靠的计算吗?
最佳答案
在您描述的情况下,您应该能够计算出您希望窗口最大化的 RECT
,并且 RECT
应该完全在一台显示器上(您正在谈论获取监视器的监视器或工作区边界并减少 RECT
,根据定义,它完全在一个监视器上)。在这种情况下,逻辑很简单。
要清楚:如果所需的最大化 RECT 溢出目标监视器,则此逻辑将不起作用。这不是 OP 的情况。
// given the HWND...
HWND hwnd = ...;
// get handles for primary and target monitor
HMONITOR hPrimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
HMONITOR hTargetMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
// prep primary and target monitor info structures
MONITORINFO primaryMonitorInfo { sizeof MONITORINFO };
MONITORINFO targetMonitorInfo { sizeof MONITORINFO };
// get primary and target monitor info
GetMonitorInfo(hPrimaryMonitor, &primaryMonitorInfo);
GetMonitorInfo(hTargetMonitor, &targetMonitorInfo);
// calculate your desired maximized RECT in absolute screen coordinates
RECT maximizedRect = ...;
// adjust the MINMAXINFO struct
MINMAXINFO* pMinMaxInfo = (MINMAXINFO)lParam;
pMinMaxInfo->ptMaxPosition = {
primaryMonitorInfo.rcMonitor.left + maximizedRect.left - targetMonitorInfo.rcMonitor.left,
primaryMonitorInfo.rcMonitor.top + maximizedRect.top - targetMonitorInfo.rcMonitor.top,
};
pMinMaxInfo->ptMaxSize = {
maximizedRect.right - maximizedRect.left,
maximizedRect.bottom - maximizedRect.top
};
关于winapi - 为多个监视器处理 WM_GETMINMAXINFO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35984883/