Capture Right-Click - Reply Event

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

Capture Right-Click - Reply Event
 
Calvin Nguyen




Posts: 15
Joined: 2006-09-29

Hi,

What is the right way to capture the event triggered when someone right-clicks a mail item in explorer view and then selects 'Reply', 'Reply All' or 'Forward'?

Should I use ADXBuiltInControl objects? If so, what are the appropriate Id values to assign to them?

Thanks a mil,

Calvin
Posted 21 Nov, 2006 17:11:24 Top
Sergey Grischenko


Add-in Express team


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

I would advise you to use the ADX Item Events class to process the Reply and ReplyAll events of the selected item. Please look at the OutlookItemEvents example from the ADX instalation package to learn how you can connect to events of Outlook items.

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 22 Nov, 2006 16:54:24 Top
Calvin Nguyen




Posts: 15
Joined: 2006-09-29

Thanks for your response, Sergey.

Correct me if I'm wrong, but the OutlookItemEvents project you're referring to contains examples of how to handle 'inspector activate', 'item send', 'inspector close', etc.

I currently use the above events. But what I'd like to do now is capture the button event that occurs when someone right-clicks an item in explorer view and then selects 'Reply'. Or equivalently, when someone selects 'Reply' from Outlook's Actions menu. I have not been able to capture these.

As an informational note, I cannot place my code in something like 'inspector activate' because my goal is to prevent the inspector from even opening if certain conditions are not met.

Please let me know how I can capture the two events I mentioned.

Thanks again,

Calvin
Posted 22 Nov, 2006 17:43:14 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Calvin, you just need to change the example a little.

1. comment out the code of the InspctorActivate event handler.
2. add the ExplorerSelectionChange event handler.
3. add the code below to the ExplorerSelectionChange event handler to
connect to the mail item from Outlook explorer.

private void adxOutlookEvents_ExplorerSelectionChange(object sender, object explorer)
{
object itemObj = null;
Outlook.Selection sel = null;
Outlook._Explorer expl = explorer as Outlook._Explorer;
try
{
try
{
sel = expl.Selection;
}
catch
{
}
if (sel != null && sel.Count == 1)
{
itemObj = sel.Item(1);
if (itemObj is Outlook._MailItem)
itemEvents.ConnectTo(itemObj, true);
else
Marshal.ReleaseComObject(itemObj);
}
}
finally
{
if (sel != null)
Marshal.ReleaseComObject(sel);
}
}


Posted 23 Nov, 2006 09:01:43 Top
Calvin Nguyen




Posts: 15
Joined: 2006-09-29
Hi Sergey,

I couldn't get your example to work in spite of the fact that your code was stepped through fine.

Just to confirm what I'm trying to do, I've attached a screenshot showing the buttons whose events I want to capture. Again, they're the 'Reply', 'Reply All' and 'Forward' buttons that appear when a user right-clicks an item in Outlook's explorer view.

[img]http://www.flickr.com/photo_zoom.gne?id=304285242&size=l[/img]

On another note, I've heard "context menu" mentioned in the forums. My previous understanding was this is the menu that appears when a folder or file is right-clicked in Windows. Is this correct? Or can the context menu be used to solve my current problem?

Thanks,

Cal
Posted 23 Nov, 2006 11:39:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Calvin, please download the following example:
http://www.add-in-express.com/projects/outlookitemevents.zip
Does it work on your PC?

The Outlook context menu is not the Windows menu. It is just a command bar in Outlook object model. The ADXBuiltInControl component can't connect to the context menu in Outlook because this menu is dynamic. If you want to use the context menu, you will have to connect to the Reply button manually in the code.
Posted 23 Nov, 2006 14:45:44 Top
Calvin Nguyen




Posts: 15
Joined: 2006-09-29

Thanks, Sergey. I think your example project is exactly what I'm looking for.

I have only one more question. How would I disable the standard action of the 'Reply' button? In the same style as setting to true the DisableStandardAction property of an ADXBuiltInControl is what I mean.
Posted 23 Nov, 2006 15:16:44 Top
Sergey Grischenko


Add-in Express team


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

I will send you an example on Monday.
Posted 24 Nov, 2006 15:07:24 Top
Sergey Grischenko


Add-in Express team


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

For some reason Outlook doesn't allow to disable the standard action of the Reply button in the context menu. Below you will find the code that you can use to connect to built-in controls manually in the add-in code.

private void ConnectToReply(Office.CommandBar msoBar)
{
try
{
if (msoBar != null)
{
Office.CommandBarButton msoButton =
this.FindControlObj(msoBar, Office.MsoControlType.msoControlButton, 354) as Office.CommandBarButton;
if (msoButton != null)
{
msoBar.Protection = Office.MsoBarProtection.msoBarNoProtection;
msoButton.Reset();
msoButton.OnAction = "!<" + this.GetProgID() + ">";
msoButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(DoMsoClick);
}
}
}
finally
{
if (msoBar != null)
Marshal.ReleaseComObject(msoBar);
}
}

private bool handled = true; // false - if you need to perform the standard action.

private void DoMsoClick(Office.CommandBarButton button, ref bool cancel)
{
cancel = handled;
}

private void adxCommandBarButton1_Click(object sender)
{
ConnectToReply(this.FindCommandBarObj("Standard") as Office.CommandBar);
}

Posted 27 Nov, 2006 12:17:26 Top