protected override void OnActivated(EventArgs e) { if (Ribbon != null) { Ribbon.Invalidate(); } base.OnActivated(e); }
/// <summary> /// Processes the WndProc for a form with a Ribbbon. Returns true if message has been handled /// </summary> /// <param name="m">Message to process</param> /// <returns><c>true</c> if message has been handled. <c>false</c> otherwise</returns> public virtual bool WndProc(ref Message m) { if (DesignMode) { return(false); } bool handled = false; if (WinApi.IsVista) { #region Checks if DWM processes the message IntPtr result; int dwmHandled = WinApi.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, out result); if (dwmHandled == 1) { m.Result = result; handled = true; } #endregion } //if (m.Msg == WinApi.WM_NCLBUTTONUP) //{ // UpdateRibbonConditions(); //} if (!handled) { if (m.Msg == WinApi.WM_NCCALCSIZE && (int)m.WParam == 1) //0x83 { #region Catch the margins of what the client area would be WinApi.NCCALCSIZE_PARAMS nccsp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(WinApi.NCCALCSIZE_PARAMS)); if (!MarginsChecked) { //Set what client area would be for passing to DwmExtendIntoClientArea SetMargins(new Padding( nccsp.rect2.Left - nccsp.rect1.Left, nccsp.rect2.Top - nccsp.rect1.Top, nccsp.rect1.Right - nccsp.rect2.Right, nccsp.rect1.Bottom - nccsp.rect2.Bottom)); MarginsChecked = true; } #region Hack to get rid of the black caption bar when form is maximized on multi-monitor setups with DWM enabled // toATwork: on multi-monitor setups the caption bar when the form is maximized the caption bar is black instead of glass // * set handled to false and let the base implementation handle it, will work but then the default caption bar // is also visible - not desired // * setting the client area to some other value, e.g. descrease the size of the client area by one pixel will // cause windows to render the caption bar a glass - not correct but the lesser of the two evils if (Screen.AllScreens.Length > 1 && WinApi.IsGlassEnabled) { nccsp.rect0.Bottom -= 1; } #endregion Marshal.StructureToPtr(nccsp, m.LParam, false); m.Result = IntPtr.Zero; handled = true; #endregion } else if (m.Msg == WinApi.WM_NCACTIVATE && Ribbon != null && Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaCustomDrawn) { Ribbon.Invalidate(); handled = true; if (m.WParam == IntPtr.Zero) // if could be removed because result is ignored if WParam is TRUE { m.Result = (IntPtr)1; } } else if ((m.Msg == WinApi.WM_ACTIVATE || m.Msg == WinApi.WM_PAINT) && WinApi.IsVista) //0x06 - 0x000F { m.Result = (IntPtr)1; handled = false; } else if (m.Msg == WinApi.WM_NCHITTEST && (int)m.Result == 0) //0x84 { m.Result = new IntPtr(Convert.ToInt32(NonClientHitTest(new Point(WinApi.LoWord((int)m.LParam), WinApi.HiWord((int)m.LParam))))); handled = true; } else if (m.Msg == WinApi.WM_SYSCOMMAND) { uint param = IntPtr.Size == 4 ? (uint)m.WParam.ToInt32() : (uint)m.WParam.ToInt64(); if ((param & 0xFFF0) == WinApi.SC_RESTORE) { Form.Size = _storeSize; } else if (Form.WindowState == FormWindowState.Normal) { _storeSize = Form.Size; } } else if (m.Msg == WinApi.WM_WINDOWPOSCHANGING || m.Msg == WinApi.WM_WINDOWPOSCHANGED) // needed to update the title of MDI parent (at least) { if (Ribbon != null) { Ribbon.Invalidate(); } } } return(handled); }
/// <summary> /// Processes the WndProc for a form with a Ribbbon. Returns true if message has been handled /// </summary> /// <param name="m">Message to process</param> /// <returns><c>true</c> if message has been handled. <c>false</c> otherwise</returns> public virtual bool WndProc(ref Message m) { if (DesignMode) { return(false); } bool handled = false; if (WinApi.IsVista) { #region Checks if DWM processes the message IntPtr result; int dwmHandled = WinApi.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, out result); if (dwmHandled == 1) { m.Result = result; handled = true; } #endregion } //if (m.Msg == WinApi.WM_NCLBUTTONUP) //{ // UpdateRibbonConditions(); //} if (!handled) { if (m.Msg == WinApi.WM_NCCALCSIZE && (int)m.WParam == 1) //0x83 { #region Catch the margins of what the client area would be WinApi.NCCALCSIZE_PARAMS nccsp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(WinApi.NCCALCSIZE_PARAMS)); if (!MarginsChecked) { //Set what client area would be for passing to DwmExtendIntoClientArea SetMargins(new Padding( nccsp.rect2.Left - nccsp.rect1.Left, nccsp.rect2.Top - nccsp.rect1.Top, nccsp.rect1.Right - nccsp.rect2.Right, nccsp.rect1.Bottom - nccsp.rect2.Bottom)); MarginsChecked = true; } Marshal.StructureToPtr(nccsp, m.LParam, false); m.Result = IntPtr.Zero; handled = true; #endregion } else if (m.Msg == WinApi.WM_NCACTIVATE && Ribbon != null && Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaCustomDrawn) { Ribbon.Invalidate(); handled = true; if (m.WParam == IntPtr.Zero) // if could be removed because result is ignored if WParam is TRUE { m.Result = (IntPtr)1; } } else if ((m.Msg == WinApi.WM_ACTIVATE || m.Msg == WinApi.WM_PAINT) && WinApi.IsVista) //0x06 - 0x000F { m.Result = (IntPtr)1; handled = false; } else if (m.Msg == WinApi.WM_NCHITTEST && (int)m.Result == 0) //0x84 { #region Check the Non-client area hit test m.Result = new IntPtr(Convert.ToInt32(NonClientHitTest(new Point(WinApi.LoWord((int)m.LParam), WinApi.HiWord((int)m.LParam))))); handled = true; if (Ribbon != null && Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaCustomDrawn) { //Kevin Carbis - this refresh call caused severe cpu usage while moving the mouse over the //caption bar. I have been trying to find a way to make a less demanding call to paint. //Form.Refresh(); //WinApi.InvalidateWindow(Form.Handle); //Form.Invalidate(); //Ribbon.Invalidate(); Ribbon.RedrawArea(Ribbon.ClientRectangle); } //Console.WriteLine("Msg " + m.Msg.ToString() + " " + m.Msg.ToString("X")); #endregion } else if ( (Ribbon != null && Ribbon.ActualBorderMode != RibbonWindowMode.NonClientAreaCustomDrawn) && (m.Msg == WinApi.WM_SYSCOMMAND || m.Msg == WinApi.WM_WINDOWPOSCHANGING || m.Msg == WinApi.WM_WINDOWPOSCHANGED)) { Ribbon.Invalidate(); } else if (m.Msg == WinApi.WM_NCMOUSELEAVE) { } } return(handled); }