|
Søren Hjarlvig
Posts: 34
Joined: 2007-02-22
|
Hello,
I'm catching the ItemSend event and if certain conditions are meet, I cancel the send event and saves the message using:
mailItem.GetInspector.Close(OlInspectorClose.olSave);
This works when using the "normal" Outlook editor, but if Word is used, I'm getting a COM exception at Outlook._MailItem.get_GetInspector.
From reading this forum, I understand that the inspector is null when using Word as mail editor.
Is a way to close the Word Editor from an ItemSend eventhandler?
Best regards
Søren
|
|
Posted 22 Feb, 2007 18:10:22
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Søren.
Did you try to use the Close method of the Outlook._MailItem interface?
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 23 Feb, 2007 13:30:28
|
|
Top
|
|
Søren Hjarlvig
Posts: 34
Joined: 2007-02-22
|
Thanks for your response. I tried Item.Close, but the result is a COM exception saying that Item.Close cannot be used during an Item.Send event...
In my ItemSend eventhandler I start a new thread. Maybe I could close the Word editor window from there, but the Item is released (Marshal.ReleaseComObject?) when the eventhandler returns and the reference becomes useless :-(
Regards
Søren |
|
Posted 23 Feb, 2007 20:47:20
|
|
Top
|
|
Søren Hjarlvig
Posts: 34
Joined: 2007-02-22
|
It seems that the COM exception is only thrown when using Outlook 2000 / Word 2000. When using Outlook XP / Word XP, Word simply crashes.
Haven't tested Office 2003 yet.
Regards
Søren |
|
Posted 25 Feb, 2007 07:59:10
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Søren.
You can use the OnSendMessage event to close the item in a separate thread. You just need to call the SendMessage method of the addinmodule with your custom message. To get the mail inspector in the OnSendMessage event handler you can use the ActiveInspector method of Outlook application.
|
|
Posted 26 Feb, 2007 07:33:26
|
|
Top
|
|
Søren Hjarlvig
Posts: 34
Joined: 2007-02-22
|
Thank you for your help so far.
I can't get the SendMessage/OnSendMessage approach to work.
In the AddinModule() constructor I have
this.adxOutlookEvents.ItemSend +=
new AddinExpress.MSO.ADXOlItemSend_EventHandler(adxOutlookEvents_ItemSend);
and
this.OnSendMessage += new AddinExpress.MSO.ADXSendMessage_EventHandler(AddinModule_OnSendMessage);
and I have:
void AddinModule_OnSendMessage(object sender, AddinExpress.MSO.ADXSendMessageEventArgs e)
{
MessageBox.Show("AddinModule_OnSendMessage");
if (this.OutlookApp.ActiveInspector() != null && e.Message == 123)
{
MessageBox.Show("Closing");
this.OutlookApp.ActiveInspector().Close(OlInspectorClose.olDiscard);
}
}
void adxOutlookEvents_ItemSend(object sender, AddinExpress.MSO.ADXOlItemSendEventArgs e)
{
new ItemSendHandler(this.OutlookApp.Application).ItemSend(e);
MessageBox.Show("SendMessage");
this.SendMessage(123, IntPtr.Zero, IntPtr.Zero);
}
When I send a message, the "SendMessage"-mbox is showing, but the "AddinModule_OnSendMessage"-mbox is not (and the inspector stays open).
I guess I'm doing something wrong ?
|
|
Posted 26 Feb, 2007 10:07:03
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Try the following code:
private const int WM_USER = 0x0400;
private const int WM_MYMESSAGE = WM_USER + 1000;
void adxOutlookEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
....
this.SendMessage(WM_MYMESSAGE, IntPtr.Zero, IntPtr.Zero);
....
}
void AddinModule_OnSendMessage(object sender, ADXSendMessageEventArgs e)
{
if (e.Message == MYMESSAGE)
{
.....
}
} |
|
Posted 26 Feb, 2007 10:21:58
|
|
Top
|
|
Søren Hjarlvig
Posts: 34
Joined: 2007-02-22
|
It works - thank you for excellent support :D |
|
Posted 26 Feb, 2007 11:13:26
|
|
Top
|
|