我遇到的问题是here。
我用
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case 0x0024: // WM_GETMINMAXINFO
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position
// to fit the work area of the correct monitor
// int MONITOR_DEFAULTTONEAREST = 0x00000002;
IntPtr monitor = MonitorFromWindow(hwnd, 0x00000002);
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.X = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top);
mmi.ptMaxSize.X = Math.Abs(rcWorkArea.Right - rcWorkArea.Left);
mmi.ptMaxSize.Y = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top);
}
Marshal.StructureToPtr(mmi, lParam, true);
var mmiAfterUpdate = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); // values are updated
handled = true;
break;
}
return IntPtr.Zero;
}
我的窗口是 WindowStyle =“ None” 和 AllowsTransparency =“ True” 我通过重新读取和转换 lparam 来检查更新值,它实际上包含更新的 ptMaxPositioen 值(0,0)而不是(-7,-7)
但是我发现,当我拖动最大化窗口时(我将鼠标光标放到较低的位置才能执行此操作), lparam 出现在 WindowProc 中,带有( -7,-7)。
有什么办法可以解决这种问题?