Ribbon is slowing down application

Disscusion: http://ribbon.codeplex.com/discussions/81454


Note: The bugs stated in this page have been solved in new version of ribbon. You can get it at new site, here: http://officeribbon.codeplex.com/


Solution 1:

GlobalHook.cs Fixed Shared by han6man*

  • Download Source Code.
  • Find GlobalHook.cs
  • Find private void InstallHook()

http://www.codeproject.com/Messages/4020406/Re-Here-is-a-Solution-that-works-for-2-0-and-4-0-n.aspx

using System.Diagnostics;

 

/// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            /// Error check
            if (Handle != 0) throw new Exception("Hook is already installed");
 
            #region htype
            int htype = 0;
 
            switch (HookType)
            {
                case HookTypes.Mouse:
                    htype = WinApi.WH_MOUSE_LL;
                    break;
                case HookTypes.Keyboard:
                    htype = WinApi.WH_KEYBOARD_LL;
                    break;
                default:
                    throw new Exception("HookType is not supported");
            }
            #endregion
 
            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);
 
            /// Hook
            //_hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);

            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, GetCurrentModule().BaseAddress, 0); // FIX
            if (_hHook == 0) _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, IntPtr.Zero, 0);  // FIX

            /// Error check
            if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
            
 
        }

Updated: 02 Jan 2013

public static ProcessModule GetCurrentModule()
{
    // need instance handle to module to create a system-wide hook
    Module[] list = System.Reflection.Assembly.GetExecutingAssembly().GetModules();
    System.Diagnostics.Debug.Assert(list != null && list.Length > 0);
    //System.Reflection.Assembly.LoadFrom("System.Windows.Forms.Ribbon.dll").ImageRuntimeVersion;
    var currentProcess = Process.GetCurrentProcess();
    var modules = currentProcess.Modules;
    ProcessModule mod = null;

    #region
    if (Environment.Version.Major < 3)
        foreach (ProcessModule m in modules)
        {
            if (m.ModuleName == list[0].Name)
            {
                mod = m;
                return mod;
            }
        }
    else if (mod == null) mod = Process.GetCurrentProcess().MainModule;

    return mod;

    #endregion
}

Solution 2:

This fix will enable you to use with MDI Client, but might experience other ribbon controls (such as dropdownlist) to refresh incorrectly.
(shared by javierdd)

  • Download the source code.
  • Find GlobalHook.cs

01.png

  • Find private void InstallHook()
  • Add a return statement at the beggining of the method so nothing is done

02.png


Solution 3:

(shared by giague)

In Ribbon.cs find

protected override void WndProc(ref Message m)


then sobstitute the proc with this one including the variable declaration

private bool MouseOnCaption = false;

It allow Dobule Click on caption bar and drag the from when in normal mode;

private bool MouseOnCaption = false;
protected override void WndProc(ref Message m)
{
    //These are constant to send Drag instruction to base.WndProc;
    const int HT_CAPTION = 0x2; const int WM_NCLBUTTONDOWN = 0xa1;
    bool bypassed = false;

    if (WinApi.IsWindows && (ActualBorderMode == RibbonWindowMode.NonClientAreaGlass || ActualBorderMode == RibbonWindowMode.NonClientAreaCustomDrawn))
    {
        if (m.Msg == WinApi.WM_NCHITTEST)
        {
            Form f = FindForm();
            Rectangle caption;
            if (RightToLeft == RightToLeft.No)
            {
                int captionLeft = QuickAcessToolbar.Visible ? QuickAcessToolbar.Bounds.Right : OrbBounds.Right;
                if (QuickAcessToolbar.Visible && QuickAcessToolbar.DropDownButtonVisible) captionLeft = QuickAcessToolbar.DropDownButton.Bounds.Right;
                caption = Rectangle.FromLTRB(captionLeft, 0, Width, CaptionBarSize);
            }
            else
            {
                int captionRight = QuickAcessToolbar.Visible ? QuickAcessToolbar.Bounds.Left : OrbBounds.Left;
                if (QuickAcessToolbar.Visible && QuickAcessToolbar.DropDownButtonVisible) captionRight = QuickAcessToolbar.DropDownButton.Bounds.Left;
                caption = Rectangle.FromLTRB(0, 0, captionRight, CaptionBarSize);
            }

            Point screenPoint = new Point(WinApi.LoWord((int)m.LParam), WinApi.HiWord((int)m.LParam));
            Point ribbonPoint = PointToClient(screenPoint);
            bool onCaptionButtons = false;

            if (CaptionButtonsVisible)
            {
                onCaptionButtons = CloseButton.Bounds.Contains(ribbonPoint) ||
                MinimizeButton.Bounds.Contains(ribbonPoint) ||
                MaximizeRestoreButton.Bounds.Contains(ribbonPoint);
            }
            //Detect if mouse is on caption andalso not on CaptionButtons
            MouseOnCaption = (!onCaptionButtons && RectangleToScreen(caption).Contains(screenPoint));
        }
        if (MouseOnCaption)
        {
            if (m.Msg == WinApi.WM_LBUTTONDBLCLK)
            {
                //If Double Click on caption change FormWindowsState
                Form f = FindForm();
                f.WindowState = f.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal;
                bypassed = true;
            }
            if (m.Msg == WinApi.WM_LBUTTONDOWN)
            {
                //If mouse left button is down on caption create and send message to start drag.
                Form f = FindForm();
                Message mDrag = new Message();
                mDrag.HWnd = f.Handle;
                mDrag.Msg = WM_NCLBUTTONDOWN;
                mDrag.WParam = new IntPtr(HT_CAPTION);
                mDrag.LParam = IntPtr.Zero;
                base.WndProc(ref mDrag);
            }
        }

    }

    if (!bypassed)
    {
        base.WndProc(ref m);
    }
}

GlobalHook.cs

Last edited Jan 3, 2013 at 1:46 PM by adriancs, version 14

Comments

han6man Jan 2, 2013 at 9:11 AM 
public static ProcessModule GetCurrentModule()
{
// need instance handle to module to create a system-wide hook
Module[] list = System.Reflection.Assembly.GetExecutingAssembly().GetModules();
System.Diagnostics.Debug.Assert(list != null && list.Length > 0);
//System.Reflection.Assembly.LoadFrom("System.Windows.Forms.Ribbon.dll").ImageRuntimeVersion;
var currentProcess = Process.GetCurrentProcess();
var modules = currentProcess.Modules;
ProcessModule mod = null;

#region
if (Environment.Version.Major < 3)
foreach (ProcessModule m in modules)
{
if (m.ModuleName == list[0].Name)
{
mod = m;
return mod;
}
}
else if (mod == null) mod = Process.GetCurrentProcess().MainModule;

return mod;

#endregion
}