none
Disabling controls of the attachment context menu in MS Outlook 2010 RRS feed

  • Question

  • Hello,

    I am able to add a CommandBarButton to the Attachment context menu by defining the below XML and loading it.

    <?xml version="1.0" encoding="utf-8" ?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    <contextMenus>
        <contextMenu idMso="ContextMenuAttachments">
          <button id="MyContextMenuAttachments" label="Label" onAction="OnMyButtonClick"/>
        </contextMenu>
    </contextMenus>
    </customUI>

    Now my requirement is to disable existing standard CommandBarButtons(Open, Save As, etc...) of the Attachment context prior to displaying the menu. As this was not possible, I tried to bind to the Application.AttachmentContextMenuDisplay() and within it bind to the click event of CommandBarButtons as follows, inorder to cancel the user selection. But although there were no errors the bound method did not trigger when the option was selected from the menu.

    private Microsoft.Office.Core.CommandBarButton btnSaveAs;
    public void MyAttachmentContextMenuDisplay(Microsoft.Office.Core.CommandBar CommandBar, Microsoft.Office.Interop.Outlook.AttachmentSelection Attachments)
    {
        Microsoft.Office.Core.CommandBarControls controls = CommandBar.Controls;
        for (int i = 1; i <= controls.Count; i++)
        {
            Microsoft.Office.Core.CommandBarControl control = controls[i];
            btnSaveAs = control as Microsoft.Office.Core.CommandBarButton;
            btnSaveAs.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnSaveAs_Click);
        }
    }
    
    public void btnSaveAs_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
    {
        CancelDefault = true;
    }
    Am I missing anything in the above?

    Therefore any help in the below areas, are greatly appreciated. Some code snippets will really help.
    => How to disable or remove standard options in the attachment context menu?
    => Is it possible to modify the above XML to achieve this?
    => How to bind to the click of each option in the attachment context menu?
    => At worst how to cancel the attachment context menu and the buttons in the attachment ribbon?

    I am using MS Outlook2010 with VS2010 C#.

    Tuesday, March 3, 2015 12:09 PM

Answers

All replies

  • Hello Damian,

    Command bars were marked as deprecated in Outlook 2010. You need to use the Fluent UI instead.

    See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

    Tuesday, March 3, 2015 12:23 PM
  • Hello Eugene,

    Thanks.

    To customize the above XML, is there any way or any reference that I could get a list of the control's idMso of the attachment menu? Or even the button's idMso of the Attachment ribbon tab?

    I tried to use the id of the controls in the XML which I got from above the btnSaveAs.Id, in MyAttachmentContextMenuDisplay() but it does not work.

    Please advice.

    Wednesday, March 4, 2015 5:30 AM
    • Proposed as answer by L.HlModerator Monday, March 9, 2015 9:03 AM
    Wednesday, March 4, 2015 6:12 AM
  • Hi,

    About extending the user interface in outlook 2010, you also could refer to:

    # Extending the User Interface in Outlook 2010

    https://msdn.microsoft.com/en-us/library/ee692172.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 4, 2015 9:35 AM
    Moderator
  • Hello,

    Thanks for all the details. Still I have a problem as follows,

    I have defined the XML as follows.

      <contextMenus>
        <contextMenu idMso="ContextMenuAttachments">
          <button idMso="SaveAttachAs" label="TestSaveAs" onAction="TestButtonClicked" getEnabled="TestButtonEnabled"/>
          <button id="MyContextMenuAttachments" label="TestNewButton" onAction="TestButtonClicked" getEnabled="TestButtonEnabled"/>
        </contextMenu>
      </contextMenus>

    And coded the events as follows,

    public void TestButtonClicked(CommandBarButton cmdBarButton, ref bool cancel)
    {
        MessageBox.Show("TestButtonClicked");
        cancel = true;
    }
    
    public bool TestButtonEnabled(CommandBarButton cmdBarButton)
    {
        return false;
    }

    Following are the observations.

    => Labels gets updated. No problem.
    => Only MyContextMenuAttachments gets disabled. Not SaveAttachAs. The Save As dialog loads from SaveAttachAs. Problem.
    But if enabled is set to "false" in the XML both options gets disabled.(enabled="false")
    => TestButtonClicked does not trigger for both options. Problem.

    Am I missing anything?

    Wednesday, March 4, 2015 12:02 PM
  • The callback will not be triggered for built-in controls, only for your custom UI.
    Wednesday, March 4, 2015 12:51 PM
  • Hi all,

    Thanks.

    If I disable or invisible a built-in control, is it possible to invoke the control's click or command from a custom control added to the menu? Any reference will be helpful.

    Or is there any alternative method to conditionally disable built-in controls of the attachment context menu?

    Please advice.

    Friday, March 6, 2015 3:31 AM
  • Hi,

    For your new issue, it is not related to your original issue, I suggest that you should open a new thread for the new issue.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 6, 2015 7:33 AM
    Moderator
  • Damian,

    You can use the ExecuteMso method of the CommandBars class to run the built-in control programmatically. You just need to pass the idMso value of the control you want to run to the method.

    Starain is right. I'd recommend asking separate questions in new forum threads. Thus, forum readers may recognize questions and answers.

    • Proposed as answer by L.HlModerator Monday, March 9, 2015 9:04 AM
    Friday, March 6, 2015 8:17 AM
  • Hi Eugene,

    Thanks. I could not figure out how to call the ExecuteMso. Any code references will be helpful.

    Also I have started a new thread with "How to call a custom command form a built-in control of the attachment menu in MS Outlook 2010".

    Saturday, March 7, 2015 5:09 AM
  • The Inspector and Explorer classes provide the CommandBars property which returns an instance of the corresponding class. You can use it to call the ExecuteMso method. Just pass the idMso from the Office 2013 Help Files: Office Fluent User Interface Control Identifiers to the method.

    • Marked as answer by Damian Muller Monday, March 9, 2015 9:36 AM
    Saturday, March 7, 2015 11:10 AM
  • Hi,

    Using the ActiveExplorer.CommandBars.ExecuteMso(<idMso>) of the Outlook application worked.

    Thank you all for the help.

    • Marked as answer by Damian Muller Monday, March 9, 2015 9:35 AM
    • Unmarked as answer by Damian Muller Monday, March 9, 2015 9:35 AM
    Monday, March 9, 2015 5:24 AM