protected override void WndProc(ref Message msg) { switch (msg.Msg) { case NativeMethods.WM_LBUTTONDOWN: if (this.OwnerComboItem != null) { this.OwnerComboItem.BitState[RadComboBoxElement.KeyboardCommandIssuedStateKey] = false; } break; case NativeMethods.WM_GETMINMAXINFO: { NativeMethods.MINMAXINFO info = (NativeMethods.MINMAXINFO) Marshal.PtrToStructure(msg.LParam, typeof(NativeMethods.MINMAXINFO)); info.ptMinTrackSize.x = this.MinimumSize.Width; info.ptMinTrackSize.y = this.MinimumSize.Height; Marshal.StructureToPtr(info, msg.LParam, true); return; } } base.WndProc(ref msg); }
private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) { NativeMethods.MINMAXINFO mmi = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(NativeMethods.MINMAXINFO)); // Adjust the maximized size and position to fit the work area of the correct monitor System.IntPtr monitor = NativeMethods.GetMonitorFromWindow(hwnd); // MinHeight and MinWidth need to be scaled from Virtual Pixels back to Logical Pixels DpiScale dpiScale = VirtualPixelScale; if (monitor != System.IntPtr.Zero) { NativeMethods.MONITORINFO monitorInfo = new NativeMethods.MONITORINFO(); NativeMethods.GetMonitorInfo(monitor, monitorInfo); NativeMethods.RECT rcWorkArea = monitorInfo.rcWork; NativeMethods.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 = DoubleToInt32(Math.Abs(rcWorkArea.right - rcWorkArea.left)); mmi.ptMaxSize.y = DoubleToInt32(Math.Abs(rcWorkArea.bottom - rcWorkArea.top)); // After much research, it appears that the MaxTrackSize is used for secondary monitors // while MaxSize is used for the primary monitor. mmi.ptMaxTrackSize.x = DoubleToInt32(Math.Abs(rcWorkArea.right - rcWorkArea.left)); mmi.ptMaxTrackSize.y = DoubleToInt32(Math.Abs(rcWorkArea.bottom - rcWorkArea.top)); mmi.ptMinTrackSize.x = GetMinWidthInScreenPixels(dpiScale); mmi.ptMinTrackSize.y = GetMinHeightInScreenPixels(dpiScale); } Marshal.StructureToPtr(mmi, lParam, true); }
private void WMGetMinMazInfo(ref Message m) { base.WndProc(ref m); NativeMethods.MINMAXINFO from = NativeMethods.MINMAXINFO.GetFrom(m.LParam); from.ptMinTrackSize = new NativeMethods.POINT(1, 1); Marshal.StructureToPtr((object)from, m.LParam, true); m.Result = IntPtr.Zero; }
private bool OnGetMinMaxInfo(ref Message m) { NativeMethods.MINMAXINFO minmax = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.MINMAXINFO)); minmax.maxTrackSize = this.MaximumSize; minmax.minTrackSize = this.MinimumSize; Marshal.StructureToPtr(minmax, m.LParam, false); return(true); }
private void WmGetMinMaxInfo(ref Message m) { NativeMethods.MINMAXINFO minmax = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure( m.LParam, typeof(NativeMethods.MINMAXINFO)); if (MaximumSize != Size.Empty) { minmax.maxTrackSize = MaximumSize; } else { Rectangle rect = Screen.GetWorkingArea(this); minmax.maxPosition = new Point( rect.X - BorderWidth, rect.Y); minmax.maxTrackSize = new Size( rect.Width + BorderWidth * 2, rect.Height + BorderWidth); } if (MinimumSize != Size.Empty) { minmax.minTrackSize = MinimumSize; } else { minmax.minTrackSize = new Size( CloseBoxSize.Width + MinimizeBoxSize.Width + MaximizeBoxSize.Width + ControlBoxOffset.X + ControlBoxSpace * 2 + SystemInformation.SmallIconSize.Width + BorderWidth * 2 + 3, CaptionHeight); } Marshal.StructureToPtr(minmax, m.LParam, false); }
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) { #region // old code commented out by ye.wang 2014-05-04 10:33:18 //// MINMAXINFO structure //NativeMethods.MINMAXINFO minMaxInfo = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure( lParam, typeof( NativeMethods.MINMAXINFO ) ); //// Get the handle of the nearest monitor to the window ////WindowInteropHelper interopHelper = new WindowInteropHelper( this ); //IntPtr hMonitor = NativeMethods.MonitorFromWindow( _wndTarget.GetHandle(), NativeMethods.MONITOR_DEFAULTTONEAREST ); //// Get monitor information //NativeMethods.MONITORINFOEX monitorInfo = new NativeMethods.MONITORINFOEX(); //monitorInfo.cbSize = Marshal.SizeOf( monitorInfo ); //NativeMethods.GetMonitorInfo( new HandleRef( this, hMonitor ), monitorInfo ); //// Get HwndSource //HwndSource source = HwndSource.FromHwnd( _wndTarget.GetHandle() ); //if ( source == null ) // // Should never be null // throw new Exception( "Cannot get HwndSource instance." ); //if ( source.CompositionTarget == null ) // // Should never be null // throw new Exception( "Cannot get HwndTarget instance." ); //// Get working area rectangle //NativeMethods.RECT workingArea = monitorInfo.rcWork; //Console.WriteLine( string.Format( "left:{0},top:{1},right:{2},bottom:{3}", monitorInfo.rcWork.Left, // monitorInfo.rcWork.Top, monitorInfo.rcWork.Right, monitorInfo.rcWork.Bottom ) ); //// Get transformation matrix //System.Windows.Media.Matrix matrix = source.CompositionTarget.TransformFromDevice; //// Convert working area rectangle to DPI-independent values //Point convertedSize = // matrix.Transform( new Point( // workingArea.Right - workingArea.Left, // workingArea.Bottom - workingArea.Top // ) ); //Point convertedPosion = // matrix.Transform( new Point( // workingArea.Left, workingArea.Top // ) ); //// Set the maximized size of the window //minMaxInfo.ptMaxSize.X = (int)convertedSize.X+6; //minMaxInfo.ptMaxSize.Y = (int)convertedSize.Y+6; //// Set the position of the maximized window //minMaxInfo.ptMaxPosition.X = (int)convertedPosion.X-WND_BORDER_DROPSHADOW_SIZE; //minMaxInfo.ptMaxPosition.Y = (int)convertedPosion.Y-WND_BORDER_DROPSHADOW_SIZE; //Console.WriteLine( string.Format( "MaxInfo : left:{0},top:{1},right:{2},bottom:{3}", // convertedPosion.X, convertedPosion.Y, convertedSize.X, convertedSize.Y ) ); //Marshal.StructureToPtr( minMaxInfo, lParam, true ); #endregion // // old code NativeMethods.MINMAXINFO mmi = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(NativeMethods.MINMAXINFO)); IntPtr monitor = NativeMethods.MonitorFromWindow(hwnd, NativeMethods.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) { NativeMethods.MONITORINFOEX monitorInfo = new NativeMethods.MONITORINFOEX(); monitorInfo.cbSize = Marshal.SizeOf(monitorInfo); NativeMethods.GetMonitorInfo(new HandleRef(this, monitor), monitorInfo); NativeMethods.RECT rcWorkArea = monitorInfo.rcWork; NativeMethods.RECT rcMonitorArea = monitorInfo.rcMonitor; //mmi.ptMaxPosition.X = ( null != this.MaxiX ? this.MaxiX.Value : Math.Abs( rcWorkArea.Left - rcMonitorArea.Left ) ) - WND_BORDER_DROPSHADOW_SIZE; //mmi.ptMaxPosition.Y = ( null != this.MaxiY ? this.MaxiY.Value : Math.Abs( rcWorkArea.Top - rcMonitorArea.Top ) ) - WND_BORDER_DROPSHADOW_SIZE; if (!_bUseCall) { // use field mmi.ptMaxPosition.X = (null != this._maxiX ? this._maxiX.Value : Math.Abs(rcWorkArea.Left - rcMonitorArea.Left)) - WND_BORDER_DROPSHADOW_SIZE; mmi.ptMaxPosition.Y = (null != this._maxiY ? this._maxiY.Value : Math.Abs(rcWorkArea.Top - rcMonitorArea.Top)) - WND_BORDER_DROPSHADOW_SIZE; } else { if (null == this._maxiX_call) { this._maxiX_call = () => null; } if (null == this._maxiY_call) { this._maxiY_call = () => null; } int?ret_x = this._maxiX_call.Invoke(); int?ret_y = this._maxiY_call.Invoke(); mmi.ptMaxPosition.X = (null != ret_x ? ret_x.Value : Math.Abs(rcWorkArea.Left - rcMonitorArea.Left)) - WND_BORDER_DROPSHADOW_SIZE; mmi.ptMaxPosition.Y = (null != ret_y ? ret_y.Value : Math.Abs(rcWorkArea.Top - rcMonitorArea.Top)) - WND_BORDER_DROPSHADOW_SIZE; } mmi.ptMaxSize.X = Math.Abs( Math.Abs(rcWorkArea.Right - rcWorkArea.Left) + WND_BORDER_DROPSHADOW_SIZE - mmi.ptMaxPosition.X); mmi.ptMaxSize.Y = Math.Abs( Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top) + WND_BORDER_DROPSHADOW_SIZE - mmi.ptMaxPosition.Y); mmi.ptMinTrackSize.X = (int)this._wndTarget.MinWidth; mmi.ptMinTrackSize.Y = (int)this._wndTarget.MinHeight; } Marshal.StructureToPtr(mmi, lParam, true); }
protected override void WndProc(ref Message m) { if (this.shape != null || this.IsMdiContainer) { switch (m.Msg) { case NativeMethods.WM_NCCALCSIZE: m.Result = IntPtr.Zero; return; case NativeMethods.WM_NCPAINT: m.Result = IntPtr.Zero; return; case NativeMethods.WM_NCACTIVATE: active = Convert.ToBoolean(m.WParam.ToInt32()); Invalidate(); m.Result = (IntPtr)1; return; case 0xAE: case 0xAF: m.Result = IntPtr.Zero; return; } } switch (m.Msg) { case NativeMethods.WM_POPUPSYSTEMMENU: WmTaskBarMenu(); break; case NativeMethods.WM_NCHITTEST: if (this.FormBorderStyle == FormBorderStyle.None && this.AllowResize) { Point pt = this.PointToClient(new Point(m.LParam.ToInt32())); m.Result = (IntPtr)GetHitTest(pt); return; } break; case NativeMethods.WM_WINDOWPOSCHANGED: if (this.IsMdiContainer) { OnLayout(new LayoutEventArgs(this, "Bounds")); } break; case NativeMethods.WM_GETMINMAXINFO: { NativeMethods.MINMAXINFO info = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.MINMAXINFO)); if (this.Parent == null) { // Get the working area of the screen that hodls the biggest part of the form. // The maximization logic will put the maximized form on this screen. Screen scr = Screen.FromControl(this); Rectangle workingArea = scr.WorkingArea; Rectangle screenRect = scr.Bounds; info.ptMaxSize.x = workingArea.Width; info.ptMaxSize.y = workingArea.Height; info.ptMaxPosition.x = workingArea.X - screenRect.X; info.ptMaxPosition.y = workingArea.Y - screenRect.Y; Marshal.StructureToPtr(info, m.LParam, false); } //else //{ // NativeMethods.POINT maxSize = new NativeMethods.POINT(); // maxSize.x = this.Parent.Width; // maxSize.y = this.Parent.Height; // NativeMethods.POINT maxPos = new NativeMethods.POINT(); // maxPos.x = this.Parent.Bounds.X; // maxPos.y = this.Parent.Bounds.Y; // info.ptMaxSize = maxSize; // info.ptMaxPosition = maxPos; // Marshal.StructureToPtr(info, m.LParam, false); //} base.WndProc(ref m); } return; } base.WndProc(ref m); }