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 ? 
alvin chan




Posts: 30
Joined: 2019-10-07
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.


For this question , I cant find the type of context = store, please refer my screenshot .

[img]https://drive.google.com/file/d/1S65c4oKO0mPvfRG7AMjukXhLPRToZJkd/view?usp=sharing[/img]


[img]https://drive.google.com/file/d/142ABsio_QAZAGuMJtQQg3SflirmvKr94/view?usp=sharing[/img]


[img]https://drive.google.com/file/d/1m6YEyIp0yywHL2vOXTD0rxYklhS4cSzq/view?usp=sharing[/img]
Posted 09 Oct, 2019 05:05:28 Top
Andrei Smolin


Add-in Express team


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

The code contains a condition; delete it. Here's a C# equivalent of what you should do:

            if (e.PropertyType == ADXRibbonControlPropertyType.Visible)
            {
                object context = e.Context;
                System.Diagnostics.Debug.WriteLine("!!! " + Microsoft.VisualBasic.Information.TypeName(context));
            }


I use the DebugView utility to get the messages sent to Debug.WriteLine(); see http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx.

The code fragment above writes this record:
[18272] !!! Store


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Oct, 2019 05:57:26 Top
alvin chan




Posts: 30
Joined: 2019-10-07
Andrei

Hello Alvin,

The code contains a condition; delete it. Here's a C# equivalent of what you should do:

if (e.PropertyType == ADXRibbonControlPropertyType.Visible)
{
object context = e.Context;
System.Diagnostics.Debug.WriteLine("!!! " + Microsoft.VisualBasic.Information.TypeName(context));
}


I use the DebugView utility to get the messages sent to Debug.WriteLine(); see http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx.

The code fragment above writes this record:
[18272] !!! Store


This only return me the type of context = store , but I want to get the PST file name or the Pst file path. How can I achieve that ?
Posted 09 Oct, 2019 20:39:57 Top
Andrei Smolin


Add-in Express team


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

Cast the context object to Outlook.Store and analyze its properties.

Regards from Belarus (GMT+3),

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




Posts: 30
Joined: 2019-10-07
Andrei Smolin writes:
Cast the context object to Outlook.Store



Hi Andrei

That's no outlook.Store object ,cannot cast to outlook.store. Please advise.

[img]https://drive.google.com/file/d/1on32vLBRObq2YtINFA3XjVsy4Pp1QIB4/view?usp=sharing[/img]
Posted 10 Oct, 2019 03:14:36 Top
Andrei Smolin


Add-in Express team


Posts: 17113
Joined: 2006-05-11
Outlook.Store is available since Outlook 2007. You need to switch to using interops of Office 2007 or higher. To do this, replace interops in the Interops folder (see your project folder) with interops from {Add-in Express installation folder}\Redistributables\Interop Assemblies\Office {version}. Then you need to remove old interop references and add new ones. If you switch from ersion-neutral interops (=interops for Office 2000), you may be required to modify some calls that refer to items within a COM collection. Say, you may need to replace SomeCollection.Items(i) with SomeCollection[i]. If I remember this right, the issue only influences C#.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Oct, 2019 04:34:13 Top
alvin chan




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

Thank you, it's working good now .

How about right click context menu on "Store" level ,can we disable the "New folder" ribbon ?

[img]https://drive.google.com/open?id=1iw9NQnZP0i4N90-iQkAnaUb-k9xwIT91[/img]
Posted 10 Oct, 2019 05:34:20 Top
Andrei Smolin


Add-in Express team


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

Put an ADXRibbonCommand components onto the add-in module. 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 store, set ADXRibbonCommand.Enabed = false on the commands, otherwise, set ADXRibbonCommand.Enabed = true.

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

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Oct, 2019 05:57:26 Top
alvin chan




Posts: 30
Joined: 2019-10-07
Andrei Smolin writes:
ADXRibbonCommand


Hi Andrei

Thank you for your reply , I have successfully set visible =false for few controls on the folderribboncontextmenu. However, I cant disable the button "New folder..." , i found the idmso from the outlook, but it seems not working , could you please check for me ?

[img]https://drive.google.com/open?id=1lbC5e9fTLWdojUaj_oHZQTIoFw7aazsi[/img]

[img]https://drive.google.com/open?id=19fuWJQNhUUUvDP_6m5Wb9M_9BNLuytbI[/img]
Posted 10 Oct, 2019 21:52:29 Top
Andrei Smolin


Add-in Express team


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

Use IdMso="NewInlineFolder" to control the state of that item in the context menu. Use IdMso="NewFolder" to control the state of the control in the Folder Ribbon tab; set the control's Enabled state in in the FolderSwitch event.

I strongly recommend that you test this code in Outlook 2010 (if you need to support it) where's no "NewInlineFolder" control.

First off, check how this control works in your Outlook 2013+. Then start Outlook 2010: clicking that control shows a New folder dialog.

The point is: since there's no IdMso="NewInlineFolder" in Outlook 2010, you'll receive a Ribbon error message. To see it, you must have the "Show add-in user interface errors" selected; see section "Get Informed about Errors in Ribbon markup" in the PDF file in the folder {Add-in Express}\Docs on your development PC.

To bypass this issue, you need to add some code to the OnRibbonBeforeCreate event of the add-in module. In the event handler, you determine the Office version loading your add-in (e.g. using ADXAddinModule.HostMajorVersion < 15) and delete the ADXRibbonCommand that has IdMso="NewInlineFolder"; find some useful code at https://www.add-in-express.com/forum/read.php?FID=5&TID=15652.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Oct, 2019 02:29:54 Top