Disable context menu item?

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

Disable context menu item?
How? 
FTGMan




Posts: 31
Joined: 2007-02-09
How do I disable an item in the main menu and in the context menu in Outlook when processing Outlook Events?

REgards Richard.
Posted 19 Feb, 2007 07:06:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Richard.

You need to find the item using the FindControlObj method of the addinmodule and set the Enabled property of the control to 'false'.



P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 19 Feb, 2007 11:28:32 Top
FTGMan




Posts: 31
Joined: 2007-02-09
Thats what I thought initially, so I tried the following

	private: System::Void OnCommandBarsUpdate(System::Object^  sender, System::EventArgs^  e) 
		 {
			 Office::CommandBar ^contextBar = (Office::CommandBar^)this->FindCommandBarObj("Context Menu");
			 if (contextBar)
			 {
				 //contextBar->Enabled=false;
				 Office::CommandBarControls ^controls=contextBar->Controls;
				 if (controls)
				 {
					System::Collections::IEnumerator ^Enum=controls->GetEnumerator();
					Enum->Reset();
					while (Enum->MoveNext())
					{
						Office::CommandBarControl ^Ctrl=(Office::CommandBarControl ^)Enum->Current;
						Ctrl->Enabled=false;
					}
				 }
			 }
		}

But it throws an exception when I try to disable it. The Crtl object is valid and in the debug tools I can see it has the correct name and Id.
What am I doing wrong, is this the wrong cast.
Posted 19 Feb, 2007 12:41:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Richard, the exception occurs because Outlook doesn't allow you to disable some specific controls that are needed to function correctly. In this situation I would advise you to find another solution.
Posted 20 Feb, 2007 06:34:45 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Richard, please try to set the Protection property of the control to 'msoBarNoProtection' before you change the Enabled property. Probably it will help.
Posted 20 Feb, 2007 07:03:19 Top
FTGMan




Posts: 31
Joined: 2007-02-09
That doesnt help either. I can set the protection, but it still causes an exception when I try to disable the item.

The same code does allow me to disable everything in the File menu though!
Posted 20 Feb, 2007 12:52:06 Top