Disable Right Click Context Menu in Microsoft Outlook

Add-in Express™ Support Service
That's what is more important than anything else

Disable Right Click Context Menu in Microsoft Outlook
Is it possible or are there any events to allow to disable the right click context menu at the folders on the left panel ? 
Jun Wei Ng


Guest


Hi There,

I would like to know, is it possible to disable the context menu when we right click at the folders on the left panel using Add-In Express ?

Please take note that the folder is our own folder created by using Add-In Express.

See the image below, the section highlighted with red circle:

[img]https://ibb.co/thH2Sc1[/img]

Is it possible to do it ?

Looking forward to your reply.

Thanks and Best Regards,
Jun Wei
Posted 01 Oct, 2019 23:13:30 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Jun,

No Office API allows disabling a context menu. You can try to disable all the Ribbon commands the context menu show. Put a number of ADXRibbonCommand components onto the add-in module; one component per item in that context menu. Add an invisible Ribbon button to the context menu and check the context object when the PropertyChanging event is raised for you to provide the Visible state of the button (always set it to False): if this is your folder, set ADXRibbonCommand.Enabed = false on all the commands. If this does not work, you can use the ADXRibbonCommand.OnAction event to cancel clicking the corresponding item.

Please check the following sections at https://www.add-in-express.com/docs/net-ribbon-components.php:
- Referring to Built-in Ribbon Controls
- Intercepting Built-in Ribbon Controls
- Disabling Built-in Ribbon Controls
- Updating Ribbon Controls at Run Time
- Determining a Ribbon Control's Context


Andrei Smolin
Add-in Express Team Leader
Posted 02 Oct, 2019 01:05:14 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Hi Support

May I know how to differential the folders that created by our add-ins and other folder ?
Posted 07 Oct, 2019 02:15:02 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Jun,

Whenever the user right-click a folder, that context menu is shown. You need to have an invisible button on it. When that that context menu is being created, a series of PropertyChanging events occurs on that button; Office uses these events to discover new values for button properties (e.g., Visible, Caption, Enabled, etc.)

When you create a folder via Outlook.MAPIFolder newFolder = someFolders.Add(), you need to read newFolder.EntryId. Accordingly, in the PropertyChanging event that Office uses to get the value of the Visible property of that button, you get the context object, cast it to Outlook.MAPIFolder, retrieve MAPIFolder.EntryId and compare it with the one you get when creating the folder.

Make sure that you check the sections that I've mentioned above; they describe all or most technical details required to solve this task.


Andrei Smolin
Add-in Express Team Leader
Posted 07 Oct, 2019 02:41:37 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Hi Support

Is that possible that I disable certain buttons on the folder's right click context menu based on the .PST ? How to do it, please advise.
Posted 07 Oct, 2019 21:13:31 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Alvin,

You can try this approach.

1) Find the IdMso of the ribbon command(s) that you need to disable; see section Referring to Built-in Ribbon Controls; see the PDF file in the folder {Add-in Express}\Docs on your development PC. The same section is available at https://www.add-in-express.com/docs/net-ribbon-components.php.

2) Put an ADXRibbonCommand component(s) onto the add-in module; set the ADXRibbonCommand.IdMso to the IdMso of the ribbon command.

3) In the PropertyChanging event of the invisible button that you add to that context menu(s), analyze the context object. If you need to disable the Ribbon command, set ADXRibbonCommand.Enabled=false. Make sure that you run this code when ADXRibbonPropertyChangingEventArgs.PropertyType is ADXRibbonControlPropertyType.Visible.


Andrei Smolin
Add-in Express Team Leader
Posted 08 Oct, 2019 01:57:07 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Hi Andrei

Thank you for your reply. May I know is it possible to get the selected folder by "Adxribboncommand on action" - right click context menu button on click event ?

Also , may I know if the context is "Store" - the data file , how do we identify it is the store created by us ? That's no option to Ctype the context , please advise.
Posted 08 Oct, 2019 08:36:01 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Alvin,

You would be able to should the context object be an Outlook.MAPIFolder representing the folder right-clicked:

private void adxRibbonCommand1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
    if(e.PropertyType == ADXRibbonControlPropertyType.Enabled)
    {
        if (e.Context is Outlook.MAPIFolder)
        {
            if ((e.Context as Outlook.MAPIFolder).Name.StartsWith("P"))
            {
                e.Value = false;
            }
        }
    }

private void adxRibbonCommand1_OnAction(object sender, IRibbonControl control, bool pressed, ADXCancelEventArgs e)
{
    object context = control.Context;
    if (context is Outlook.MAPIFolder)
    {
        if ((context as Outlook.MAPIFolder).Name.StartsWith("S"))
        {
            MessageBox.Show("No-no!");
            e.Cancel = true;
        }
    }
    if (context != null) Marshal.ReleaseComObject(context); context = null;
}
}


The first event handler has this problem: Outlook updates the context and this raises the PropertyChanging event only when you right-click a folder for the first time.
The second event handler has this problem: Outlook supplies the current Outlook.Explorer object, not the folder right-clicked.

I believe this is an issue in Outlook.

You can identify a store using its StoreID, DisplayName, or FilePath (if this is a file store). To do this, you must know the StoreId, DisplayName or FilePath of your store; say, you get this information if the store is created by your code. At https://docs.microsoft.com/en-us/office/vba/outlook/how-to/navigation/best-practices-for-getting-and-setting-properties, they say that it is possible to use PropertyAccessor to add a custom property to the Store object (in order to identify it); I've never seen an example though.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Oct, 2019 03:10:39 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Dear Andrei

Thank you for your reply. The second event handler you mentioned was only supplies the active folder not the right clicked folder ,anyway to get the right clicked folder ?


For the "right click context menu" on the store, that's no "Outlook.store" option for the context , how to cast it if the type is "Store" ?
Posted 09 Oct, 2019 03:33:26 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
alvin chan writes:
The second event handler you mentioned was only supplies the active folder not the right clicked folder ,anyway to get the right clicked folder ?


Here's what I wrote about this:

Andrei Smolin writes:
The second event handler has this problem: Outlook supplies the current Outlook.Explorer object, not the folder right-clicked.

I believe this is an issue in Outlook.


A way to bypass this is to use an invisible Ribbon button on that context menu.

alvin chan writes:
For the "right click context menu" on the store


You should use the context menu named "ContextMenuStore": an invisible button in that context menu should get the Store object context in the PropertyChanged event.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Oct, 2019 03:44:12 Top