/// <summary> /// Pobranie min/max rozmiaru okna dla naszego okna /// </summary> /// <param name="hwnd"></param> /// <param name="lParam"></param> private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) { GetCursorPos(out var lMousePosition); var lCurrentScreen = mBeingMoved ? MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONULL) : MonitorFromWindow(hwnd, MonitorOptions.MONITOR_DEFAULTTONULL); var lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY); var lCurrentScreenInfo = new MONITORINFO(); if (GetMonitorInfo(lCurrentScreen, lCurrentScreenInfo) == false) { return; } var lPrimaryScreenInfo = new MONITORINFO(); if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false) { return; } mMonitorDpi = VisualTreeHelper.GetDpi(mWindow); mLastScreen = 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 / (float)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 / (float)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.RCWork.Bottom; var minSize = new Point(mWindow.MinWidth * mMonitorDpi.Value.DpiScaleX, mWindow.MinHeight * mMonitorDpi.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.RCMonitor.Left - lCurrentScreenInfo.RCWork.Left) / mMonitorDpi.Value.DpiScaleX, (lCurrentScreenInfo.RCMonitor.Top - lCurrentScreenInfo.RCWork.Top) / mMonitorDpi.Value.DpiScaleY, (lCurrentScreenInfo.RCMonitor.Right - lCurrentScreenInfo.RCWork.Right) / mMonitorDpi.Value.DpiScaleX, (lCurrentScreenInfo.RCMonitor.Bottom - lCurrentScreenInfo.RCWork.Bottom) / mMonitorDpi.Value.DpiScaleY ); mScreenSize = new Rect(lCurrentScreenInfo.RCWork.Left, lCurrentScreenInfo.RCWork.Top, currentWidth, currentHeight); }
static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);