/// <summary> /// Processes incoming Windows Messages. /// </summary> /// <param name="m">The Windows <see cref="T:System.Windows.Forms.Message" /> to process.</param> protected override void WndProc(ref Message m) { if (!this.DesignMode) { switch (m.Msg) { //Remove NoClientArea case NativeConstants.WM_NCCALCSIZE: if (m.WParam == IntPtr.Zero) { NativeStructs.RECT rect = (NativeStructs.RECT)m.GetLParam(typeof(NativeStructs.RECT)); Rectangle drawingRect = rect.ToRectangle(); drawingRect.Inflate(8, 8); Marshal.StructureToPtr(new NativeStructs.RECT(drawingRect), m.LParam, true); } else { NativeStructs.NCCALCSIZE_PARAMS calcSizeParams = (NativeStructs.NCCALCSIZE_PARAMS)m.GetLParam(typeof(NativeStructs.NCCALCSIZE_PARAMS)); Rectangle drawingRect = calcSizeParams.rgrc0.ToRectangle(); drawingRect.Inflate(8, 8); calcSizeParams.rgrc0 = new NativeStructs.RECT(drawingRect); Marshal.StructureToPtr(calcSizeParams, m.LParam, true); } m.Result = IntPtr.Zero; break; //Prevent activation of the nonclientarea case NativeConstants.WM_NCACTIVATE: m.Result = IntPtr.Zero; return; } base.WndProc(ref m); switch (m.Msg) { case NativeConstants.WM_SIZE: m.Result = IntPtr.Zero; return; } } else { base.WndProc(ref m); } }
protected override void WndProc(ref Message m) { switch ((NativeEnums.WM)m.Msg) { case NativeEnums.WM.NCCALCSIZE: //Crop the form to remove the windows borders if (m.WParam.Equals(IntPtr.Zero)) { NativeStructs.RECT rc = (NativeStructs.RECT)m.GetLParam(typeof(NativeStructs.RECT)); Rectangle r = CropForm(rc); Marshal.StructureToPtr(new NativeStructs.RECT(r), m.LParam, true); } else { NativeStructs.NCCALCSIZE_PARAMS csp = (NativeStructs.NCCALCSIZE_PARAMS)m.GetLParam(typeof(NativeStructs.NCCALCSIZE_PARAMS)); Rectangle r = CropForm(csp.rgrc0); csp.rgrc0 = new NativeStructs.RECT(r); Marshal.StructureToPtr(csp, m.LParam, true); } m.Result = IntPtr.Zero; return; case NativeEnums.WM.SIZE: if (this.WindowState != lastState) { lastState = this.WindowState; if (this.WindowState == FormWindowState.Maximized) { OverrideSize = this.RestoreBounds.Size; } NativeMethods.SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, 0, 0, NativeEnums.SWP.FRAMECHANGED | NativeEnums.SWP.NOACTIVATE | NativeEnums.SWP.NOMOVE | NativeEnums.SWP.NOSIZE | NativeEnums.SWP.NOZORDER); this.Refresh(); } break; } base.WndProc(ref m); }