WizKid730

Assuming this sample code line....

This Adds an Event Handler to the Item Reply

((Outlook.ItemEvents_10_Event)currentlySelectedMailItem).Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(my_Reply);

This handles the Event and removes the Event Handler

void my_Reply(object Response, ref bool Cancel)

{

if (Response is Outlook.MailItem)

{

currentMailItem = Response as Outlook.MailItem;

//

ReplyInspector_NewInspector(currentMailItem.GetInspector);

((Outlook.ItemEvents_10_Event)currentlySelectedMailItem).Reply -= new
Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler
(my_Reply);

currentMailItem.Display(System.Type.Missing);

Cancel = true;

}

}

Question: Is there a way to test an item's Event Handlers to see if a particular Handler is alread a member of the Event's collection




Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

Mike Walker

You have to create a collection of the mailitems to realise what objects have previously been registered to with an event. Hope that makes sense but there is no easy way to query the object.

Regards






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

WizKid730

Thanks for the quick response Mike,

So, assuming the following setup

internal static Outlook.MailItem currentlySelectedMailItem;

currentlySelectedMailItem = (Outlook.MailItem)theCurrentExplorer.Selection[1];

((Outlook.ItemEvents_10_Event)currentlySelectedMailItem).Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(my_Reply);

Question: When the Explorer selection changes and "currentlySelectedMailItem" is reassigned, the Event Handlers that were assigned earlier are lost






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

Mike Walker

I dont think you could declare as static but as the Explorer selection changes you would still have a reference in memory to the time this item was ran. Therefore currentlySelectedMailItem would be defined the first time and any even on that item would then be fired as required but I would not get too rich in loads of events as they scroll through the explorer and work on the action against the explorer and then on a new Inspector window then register this in a collection and register the events.

Regards






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

WizKid730

Thanks again, Mike.

Maybe this question is more clear.

Question: Where is the correct place to register for the REPLY, REPLYALL and FORWARD events Erics' book says these are item events. Is there application events for them also

My thinking is, if they are Item events they must be registered when the Item is selected. I am wondering if the registration of Event Handlers presists on the Item or are they part of the Variable that belongs to my addin, thereby, going away if I reassign the variable.

Also, when the Event fires and calls my routine

as in...

void my_Reply(object Response, ref bool Cancel)

does the "Response" object contain the Event Handler

regards,






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

Sue Mosher - Outlook MVP

They are all item-level events. As Mike said, the standard approach is to maintain a collection of items that are open or selected -- in other words, those to which the user could apply the Reply, Reply All or Forward command. The event handlers persist as long as the item objects are in scope. You might find Helmut's C# sample at http://www.outlookcode.com/codedetail.aspx id=797 useful, as it handles the MailItem.Open event with a wrapper class. It deals only with items opened with NewInspector, not items selected in a folder, but I think it will help you see the technique.

The Response object is the reply or forward MailItem created by the Reply, Reply All or Forward command.





Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

WizKid730

Greetings Sue,

I will definitely check out Helmut's sample, I respect his angles, however respecting yours just as much, I think the following...since a user can open a message for reading and then select reply which opens a new message for compose, they can also just select a message from the Explorer, right click and select reply, replyall or forward. What is the correctway to apply the handler to cover that case

regards,






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

Sue Mosher - Outlook MVP

Right-clicking on a message doesn't fire a SelectionChange event, so too handle that case, you'd probably want to add all the items in that folder to the wrapper class.

At this point, I'm wondering just what you're trying to accomplish with item-level event handlers. If we knew that, maybe someone could suggest an approach that isn't so complicated.





Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

WizKid730

It is unfortunate that right-click does not envoke a item change to the explorer, being that it does marque the item but does not highlight it, you can reply by right-clicking while your current selection is otherwise. This behavior is peculiar. So, I am wanting to know what is the best way to capture ALL of the ways a user can reply, replyall or forward an item from the explorer.

Is there a way to tell when an item is opening, that it is a reply and not just a read.

I am good with applying the events I need to a (static internal var or collection) as the user selects an email item or moves to another as a left-click but the fact that they can jump to an item with a right-click and then select the context menu-Reply...etc is perplexing.

Examining all samples I have seen, do not handle the way people work.






Re: Visual Studio Tools for Office Question regarding Addin Event Handlers

Sue Mosher - Outlook MVP

When an item opens, you can tell whether it's a reply, forward, etc. by looking at the values of the Size, Subject, Sent, and Recipients.Count properties.

If you want to handle all events for all visible items, you'd need to put each one in a MailItem wrapper cass.