none
How to access ribbon object or ribboncontrol object that not from ribbon callback? RRS feed

  • Question

  • I am developing a addin for outlook via c++.

    I want to access ribbon object or ribbon control so that I can disable a ribbon control in ribbon at any time.

    I know to access ribbon object in c# like this: Globals.ribbons.myribbon

    Can anybody know how to access ribbon object via c++?

    I appreciate you tips.

    Thanks.

    Wednesday, January 15, 2014 3:31 AM

Answers

  • Hello zsmj01,

    A possible dynamism in the Ribbon UI can be implemented using callbacks. You can use the getEnabled callback of your controls and assign false or true to the passed argument. Here is the signature of the callback:

    C#: bool GetEnabled(IRibbonControl control)
    
    
    VBA: Sub GetEnabled(control As IRibbonControl, ByRef enabled)
    
    
    C++: HRESULT GetEnabled([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfEnabled)
    
    
    Visual Basic: Function GetEnabled(control as IRibbonControl) As Boolean
    When required (in your case - the SelectionChange event handler) you can call the Invalidate method of the IRibbonUI interface for updating the UI, callbacks will be invoked by the host application.



    • Edited by Eugene Astafiev Friday, January 17, 2014 3:29 PM
    • Marked as answer by zsmj01 Saturday, January 18, 2014 2:35 AM
    Friday, January 17, 2014 3:24 PM
  • When Explorer.SelectionChange() fires you can handle the event. In the event handler make a ribbon Invalidate() or InvalidateControl() call and if you've set up the ribbon XML with callbacks for getEnabled() you can decide whether or not to enable the control.

    However, that has to be done with ribbon callbacks and in general the class that implements Extensibility must also implement the ribbon interfaces, and that has to be done in an Outlook COM addin.


    Ken Slovak MVP - Outlook

    • Marked as answer by zsmj01 Saturday, January 18, 2014 2:35 AM
    Friday, January 17, 2014 3:29 PM
    Moderator

All replies

  • Hello zsmj01,

    If you need to add a custom Ribbon UI in the add-in you have to implement IRibbonExtensibility interface. You can read more about this in the Building a C++ Add-in for Outlook 2010 article.

    Wednesday, January 15, 2014 8:12 AM
  • Thank you for your reply.

    I have read the article before. The article doesn't point to how to access ribbon object or ribbon control。

    I know I can get ribbon control object from callback function of ribbon control.

    But I do not want to get one of these objects through ribbon-control-objcet callback function.

    And the ribbon object isn't a argument of ribbon-control-objcet callback function.


    • Edited by zsmj01 Wednesday, January 15, 2014 10:57 AM
    Wednesday, January 15, 2014 10:53 AM
  • The Ribbon UI is a static thing from its birth and you can't operate it as you did in case of command bar controls. The only possible dynamism is callbacks.

    Why do you need to access a ribbon object? What exactly do you want to implement?

    Finally, the Customizing the 2007 Office Fluent Ribbon for Developers series of articles describes the Fluent UI in depth.

    Wednesday, January 15, 2014 11:56 AM
  • The Ribbon UI is a static thing from its birth and you can't operate it as you did in case of command bar controls. The only possible dynamism is callbacks.

    Why do you need to access a ribbon object? What exactly do you want to implement?

    Finally, the Customizing the 2007 Office Fluent Ribbon for Developers series of articles describes the Fluent UI in depth.

    What I want to implement is I can enable the ribbon control or not when user change folder in Outlook.The explorer component has a event named 'SelectionChange'.

    http://msdn.microsoft.com/en-US/library/vstudio/microsoft.office.interop.outlook.explorer_members.aspx


    • Edited by zsmj01 Friday, January 17, 2014 9:52 AM
    Friday, January 17, 2014 9:51 AM
  • Hello zsmj01,

    A possible dynamism in the Ribbon UI can be implemented using callbacks. You can use the getEnabled callback of your controls and assign false or true to the passed argument. Here is the signature of the callback:

    C#: bool GetEnabled(IRibbonControl control)
    
    
    VBA: Sub GetEnabled(control As IRibbonControl, ByRef enabled)
    
    
    C++: HRESULT GetEnabled([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfEnabled)
    
    
    Visual Basic: Function GetEnabled(control as IRibbonControl) As Boolean
    When required (in your case - the SelectionChange event handler) you can call the Invalidate method of the IRibbonUI interface for updating the UI, callbacks will be invoked by the host application.



    • Edited by Eugene Astafiev Friday, January 17, 2014 3:29 PM
    • Marked as answer by zsmj01 Saturday, January 18, 2014 2:35 AM
    Friday, January 17, 2014 3:24 PM
  • When Explorer.SelectionChange() fires you can handle the event. In the event handler make a ribbon Invalidate() or InvalidateControl() call and if you've set up the ribbon XML with callbacks for getEnabled() you can decide whether or not to enable the control.

    However, that has to be done with ribbon callbacks and in general the class that implements Extensibility must also implement the ribbon interfaces, and that has to be done in an Outlook COM addin.


    Ken Slovak MVP - Outlook

    • Marked as answer by zsmj01 Saturday, January 18, 2014 2:35 AM
    Friday, January 17, 2014 3:29 PM
    Moderator
  • Thank Eugene Astafiev and Ken Slovak very much.

    I use GetEnabled callback solve the problem.

    Appreciation!

    http://social.msdn.microsoft.com/Forums/office/en-US/220815a2-0ccf-4ee3-b6e4-f2a33e5563df/confused-over-getenabled-for-ribbon?forum=accessdev

    This point to how to set up the Ribbon XML with callbacks for GetEnabled.

    Saturday, January 18, 2014 2:42 AM