static extern bool GetMonitorInfo(IntPtr hMonitor, Monitorinfo lpmi);
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) { GetCursorPos(out var lMousePosition); var lCurrentScreen = _beingMoved ? MonitorFromPoint(lMousePosition, MonitorOptions.MonitorDefaulttonull) : MonitorFromWindow(hwnd, MonitorOptions.MonitorDefaulttonull); var lPrimaryScreen = MonitorFromPoint(new Point(0, 0), MonitorOptions.MonitorDefaulttoprimary); var lCurrentScreenInfo = new Monitorinfo(); if (GetMonitorInfo(lCurrentScreen, lCurrentScreenInfo) == false) { return; } var lPrimaryScreenInfo = new Monitorinfo(); if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false) { return; } _monitorDpi = VisualTreeHelper.GetDpi(_window); _lastScreen = lCurrentScreen; var currentX = lCurrentScreenInfo.RCWork.Left - lCurrentScreenInfo.RCMonitor.Left; var currentY = lCurrentScreenInfo.RCWork.Top - lCurrentScreenInfo.RCMonitor.Top; var currentWidth = (lCurrentScreenInfo.RCWork.Right - lCurrentScreenInfo.RCWork.Left); var currentHeight = (lCurrentScreenInfo.RCWork.Bottom - lCurrentScreenInfo.RCWork.Top); var currentRatio = (float)currentWidth / currentHeight; var primaryX = lPrimaryScreenInfo.RCWork.Left - lPrimaryScreenInfo.RCMonitor.Left; var primaryY = lPrimaryScreenInfo.RCWork.Top - lPrimaryScreenInfo.RCMonitor.Top; var primaryWidth = (lPrimaryScreenInfo.RCWork.Right - lPrimaryScreenInfo.RCWork.Left); var primaryHeight = (lPrimaryScreenInfo.RCWork.Bottom - lPrimaryScreenInfo.RCWork.Top); var primaryRatio = (float)primaryWidth / primaryHeight; if (lParam != IntPtr.Zero) { var lMmi = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo)); lMmi.PointMaxPosition.X = lPrimaryScreenInfo.RCMonitor.Left; lMmi.PointMaxPosition.Y = lPrimaryScreenInfo.RCMonitor.Top; lMmi.PointMaxSize.X = lPrimaryScreenInfo.RCMonitor.Right; lMmi.PointMaxSize.Y = lPrimaryScreenInfo.RCMonitor.Bottom; var minSize = new System.Windows.Point(_window.MinWidth * _monitorDpi.Value.DpiScaleX, _window.MinHeight * _monitorDpi.Value.DpiScaleX); lMmi.PointMinTrackSize.X = (int)minSize.X; lMmi.PointMinTrackSize.Y = (int)minSize.Y; Marshal.StructureToPtr(lMmi, lParam, true); } CurrentMonitorSize = new Rectangle(currentX, currentY, currentWidth + currentX, currentHeight + currentY); CurrentMonitorMargin = new Thickness( (lCurrentScreenInfo.RCWork.Left - lCurrentScreenInfo.RCMonitor.Left) / _monitorDpi.Value.DpiScaleX, (lCurrentScreenInfo.RCWork.Top - lCurrentScreenInfo.RCMonitor.Top) / _monitorDpi.Value.DpiScaleY, (lCurrentScreenInfo.RCMonitor.Right - lCurrentScreenInfo.RCWork.Right) / _monitorDpi.Value.DpiScaleX, (lCurrentScreenInfo.RCMonitor.Bottom - lCurrentScreenInfo.RCWork.Bottom) / _monitorDpi.Value.DpiScaleY ); _screenSize = new Rect(lCurrentScreenInfo.RCWork.Left, lCurrentScreenInfo.RCWork.Top, currentWidth, currentHeight); }