E
Eddie
I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.
Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuButton_Click);
Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.olMenu;
conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_CustomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}
void Items_ItemAdd(object Item)
{
// this isn't called, why?
}
void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?
MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}
I ran into few problems. I hope somebody could answer my questions.
Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuButton_Click);
Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.olMenu;
conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_CustomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}
void Items_ItemAdd(object Item)
{
// this isn't called, why?
}
void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?
MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}