View Single Post
  #10  
Old February 9th 09, 01:31 PM posted to microsoft.public.outlook.program_addins
Azhar
external usenet poster
 
Posts: 5
Default Context Menu on items


I am trying to add a menu item in the outlook context menu, the code I have
in C# is as follows..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using Microsoft.Office.Tools.Outlook;
using Microsoft.Office.Core;
using Microsoft.VisualStudio.Tools.Applications.Runtime;

namespace ContextMenu
{
public partial class ThisAddIn
{

//---

private Microsoft.Office.Core.CommandBars mCommandBars;




private void ThisApplication_OnCBarsUpdate()
{
foreach (Microsoft.Office.Core.CommandBar bar in
Application.ActiveExplorer().CommandBars)
{
if (bar.Name == "Context Menu")
{
MsoBarProtection oldProtection = bar.Protection;
bar.Protection = 0;

foreach (Office.CommandBarControl ctrl in
bar.Controls)
{
if (ctrl.Caption == "Ask to this person")
{
return;
}
}


CommandBarButton checkInMenuItem =
(CommandBarButton)bar.FindControl(MsoControlType.m soControlButton,
Type.Missing, "Ask to this person", Type.Missing, Type.Missing);



if (checkInMenuItem == null)
{
checkInMenuItem =
(CommandBarButton)bar.Controls.Add(MsoControlType. msoControlButton,
Type.Missing, Type.Missing, Type.Missing, true);
checkInMenuItem.Caption = "Ask to this person";

checkInMenuItem.Click += new
_CommandBarButtonEvents_ClickEventHandler(checkInM enuItem_Click);
}


//bar.Controls.Add(Microsoft.Office.Core.MsoControlT ype.msoControlButton,
//missing, missing, missing, false);


//button.Caption = "Track Discussion";
//button.Visible = true;
bar.Protection = oldProtection;
}
}
}

void checkInMenuItem_Click(CommandBarButton Ctrl, ref bool
CancelDefault)
{
MessageBox.Show("test");
}


//protected void checkInMenuItem_Click(object sender, System)
//{
// MessageBox.Show("Ask to this person");
//}

//---
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
mCommandBars = Application.ActiveExplorer().CommandBars;
mCommandBars.OnUpdate += new

Microsoft.Office.Core._CommandBarsEvents_OnUpdateE ventHandler(ThisApplication_OnCBarsUpdate);

}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{

}




#region VSTO generated code

/// summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// /summary
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion




}

}


But the menu item is not being displayed. Please help me get this problem
solved..

"Ken Slovak - [MVP - Outlook]" wrote:

You can't load the libraries it's what's referenced when you compile.

You would create a project to create a DLL and use the Outlook.12 library
for that (Outlook 2007). The main code only references the earliest version
of Outlook you need to support. If that code discovers that
Outlook.Application.Version.StartsWith("12") == true then it loads the DLL
that handles the Outlook 2007 context menus and doesn't instantiate the
CommandBars.OnUpdate() event handler since context menus will be handled
using that DLL.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


wrote in message
...
Ok, so at first I have to load the Outlook 10 library in order to
detect the version and then if it is the 2007 version I load its
library, correct?

Thanx,
Ivan



Ads