If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
VSTO Outlook 2003 - problem with actions
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_Clic kEventHandler(menuButton_Click); Outlook.NameSpace ns = Application.GetNamespace("MAPI"); contacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts); contacts.Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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.ol Menu; conItem.CustomAction += new Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(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? } |
Ads |
#2
|
|||
|
|||
VSTO Outlook 2003 - problem with actions
1. Why do you expect Items.ItemAdd event to fire? You are not addng new
items to the Contacts folder. 2. Items collection must be stored in a class member to make sure it is alive at all times. You do not have even a local variable, only an implicit one created by the contacts.Items.ItemAdd += new ... As soon as GC runs, that implicit variable will be release and you will never get any events. You need something like Outlook.Items Items; //must a class member .... Items = contacts.Items; Items.ItemAdd += new ... 3. conItem will end up pointing to the last item in the foreach loop. Similar to #2, you need to store the items that you need to sink events from in a list to make sure they are alive. You cannot use a single variable, each item must be stored separately and be alive as long as you trakc the events. Also note that sinking events from potemtially thousands of items is a terrible idea. 4. In your CustomAction event handler you never even check *which* custom action is firing. At the very least, check the Action.Name property to make sure you get the expected action. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Eddie" wrote in message ... 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_Clic kEventHandler(menuButton_Click); Outlook.NameSpace ns = Application.GetNamespace("MAPI"); contacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts); contacts.Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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.ol Menu; conItem.CustomAction += new Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(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? } |
#3
|
|||
|
|||
VSTO Outlook 2003 - problem with actions
Hi there!
Yes, I'm adding new items at runtime manually. I think there shouldn't be any problems with it. I agree with You. Putting all my contacts into some collection object isn't a good idea. I found some examples which are showing context menu modification, just before they get fired. This sample i saw, was made using Application_ItemCOntextMenu. But my application object don't have this event. I fought my CustomAction is only fired by action which I created, because my event handler is added only to it. I think all my problems are bacause GC, gets my objects. I will try to fix it using your hints. Thank you, for your help. "Dmitry Streblechenko" wrote: 1. Why do you expect Items.ItemAdd event to fire? You are not addng new items to the Contacts folder. 2. Items collection must be stored in a class member to make sure it is alive at all times. You do not have even a local variable, only an implicit one created by the contacts.Items.ItemAdd += new ... As soon as GC runs, that implicit variable will be release and you will never get any events. You need something like Outlook.Items Items; //must a class member .... Items = contacts.Items; Items.ItemAdd += new ... 3. conItem will end up pointing to the last item in the foreach loop. Similar to #2, you need to store the items that you need to sink events from in a list to make sure they are alive. You cannot use a single variable, each item must be stored separately and be alive as long as you trakc the events. Also note that sinking events from potemtially thousands of items is a terrible idea. 4. In your CustomAction event handler you never even check *which* custom action is firing. At the very least, check the Action.Name property to make sure you get the expected action. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Eddie" wrote in message ... 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_Clic kEventHandler(menuButton_Click); Outlook.NameSpace ns = Application.GetNamespace("MAPI"); contacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts); contacts.Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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.ol Menu; conItem.CustomAction += new Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(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? } |
#4
|
|||
|
|||
VSTO Outlook 2003 - problem with actions
Hi there!
Yes, I'm adding new items at runtime manually. I think there shouldn't be any problems with it. I agree with You. Putting all my contacts into some collection object isn't a good idea. I found some examples which are showing context menu modification, just before they get fired. This sample i saw, was made using Application_ItemCOntextMenu. But my application object don't have this event. I fought my CustomAction is only fired by action which I created, because my event handler is added only to it. I think all my problems are because GC, gets my objects. I will try to fix it using your hints. Thank you, for your help. "Dmitry Streblechenko" wrote: 1. Why do you expect Items.ItemAdd event to fire? You are not addng new items to the Contacts folder. 2. Items collection must be stored in a class member to make sure it is alive at all times. You do not have even a local variable, only an implicit one created by the contacts.Items.ItemAdd += new ... As soon as GC runs, that implicit variable will be release and you will never get any events. You need something like Outlook.Items Items; //must a class member .... Items = contacts.Items; Items.ItemAdd += new ... 3. conItem will end up pointing to the last item in the foreach loop. Similar to #2, you need to store the items that you need to sink events from in a list to make sure they are alive. You cannot use a single variable, each item must be stored separately and be alive as long as you trakc the events. Also note that sinking events from potemtially thousands of items is a terrible idea. 4. In your CustomAction event handler you never even check *which* custom action is firing. At the very least, check the Action.Name property to make sure you get the expected action. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Eddie" wrote in message ... 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_Clic kEventHandler(menuButton_Click); Outlook.NameSpace ns = Application.GetNamespace("MAPI"); contacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts); contacts.Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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.ol Menu; conItem.CustomAction += new Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(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? } |
#5
|
|||
|
|||
VSTO Outlook 2003 - problem with actions
Context menu events are only exposed in Outlook 2007, not in any previous
version of Outlook. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Eddie" wrote in message ... Hi there! Yes, I'm adding new items at runtime manually. I think there shouldn't be any problems with it. I agree with You. Putting all my contacts into some collection object isn't a good idea. I found some examples which are showing context menu modification, just before they get fired. This sample i saw, was made using Application_ItemCOntextMenu. But my application object don't have this event. I fought my CustomAction is only fired by action which I created, because my event handler is added only to it. I think all my problems are because GC, gets my objects. I will try to fix it using your hints. Thank you, for your help. "Dmitry Streblechenko" wrote: 1. Why do you expect Items.ItemAdd event to fire? You are not addng new items to the Contacts folder. 2. Items collection must be stored in a class member to make sure it is alive at all times. You do not have even a local variable, only an implicit one created by the contacts.Items.ItemAdd += new ... As soon as GC runs, that implicit variable will be release and you will never get any events. You need something like Outlook.Items Items; //must a class member .... Items = contacts.Items; Items.ItemAdd += new ... 3. conItem will end up pointing to the last item in the foreach loop. Similar to #2, you need to store the items that you need to sink events from in a list to make sure they are alive. You cannot use a single variable, each item must be stored separately and be alive as long as you trakc the events. Also note that sinking events from potemtially thousands of items is a terrible idea. 4. In your CustomAction event handler you never even check *which* custom action is firing. At the very least, check the Action.Name property to make sure you get the expected action. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Eddie" wrote in message ... 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_Clic kEventHandler(menuButton_Click); Outlook.NameSpace ns = Application.GetNamespace("MAPI"); contacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts); contacts.Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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.ol Menu; conItem.CustomAction += new Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(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? } |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2003 and VSTO questions | Christie | Add-ins for Outlook | 0 | November 3rd 06 07:19 AM |
Launch a Batch Task from Outlook 2003 - Custom Actions ? | Steph | Outlook and VBA | 0 | August 22nd 06 06:14 AM |
VSTO - Market Share of Outlook 2003 (Pro)? | Tadwick | Add-ins for Outlook | 0 | July 30th 06 05:14 AM |
VSTO Backwards compatibility with Outlook 2003 / 2007 | abcomp | Add-ins for Outlook | 1 | July 19th 06 04:14 PM |
VSTO plugin + Distribution List resolution problem.. | Sanjay | Add-ins for Outlook | 6 | May 12th 06 06:44 PM |