How to get hold of the Create Message Event

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

How to get hold of the Create Message Event
 
Ganesh Agrawal




Posts: 8
Joined: 2004-11-01
First I want to get hold of the Create New Message Event in Outlook 2003.

Second I want to add a Command Bar Buton to the New Message Inspector Window.

I am doing following but am not getting the control when I hit the Create New Message.

Any help is appreciated.

Thanks
Ganesh



***************************************************
Microsoft.Office.Interop.Outlook.Inspectors inspectors = applicationObject .Inspectors;
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(OnNewInspector);



private void OnNewInspector(Microsoft.Office.Interop.Outlook.Inspector inspector)
{
MessageBox.Show("Great");
}
***************************************************
Posted 01 Nov, 2004 21:56:55 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Ganesh,

Outlook hasn't got the Create New Message Event but you can use the NewInspector event to add your button to a command bar in new mail inpector. See the following code:

private void AddinModule_OlNewInspector(object sender, object inspector, string folderName)
{
Office.CommandBar objStandardBar;
Office.CommandBarButton btnCombine;

Outlook._Inspector olInspector = inspector as Outlook._Inspector;
object item = olInspector.CurrentItem;
if (item is Outlook._MailItem)
{
Outlook._MailItem mailItem = item as Outlook._MailItem;
if (mailItem.To == null && !mailItem.Sent)
{
// this is a new mail
try
{
objStandardBar = olInspector.CommandBars["Standard"];
btnCombine = objStandardBar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing,
"My Unique Button", true, true) as Office.CommandBarButton;
if (btnCombine == null)
{
btnCombine = objStandardBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing,
Type.Missing, Type.Missing, true) as Office.CommandBarButton;
btnCombine.Caption = "My Button";
btnCombine.Tag = "My Unique Button";
}
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message, e.Source);
}
}
Marshal.ReleaseComObject(item);
}
}
Posted 02 Nov, 2004 06:07:30 Top
Ganesh Agrawal




Posts: 8
Joined: 2004-11-01
Thanks Sergey.

I am *not* hitting the code when I try to create New Message.

Am I missing something here like registering the event.

The complete code is as follows

private void AddinModule_OlNewInspector(object sender, object inspector, string folderName)
{
Microsoft.Office.Core.CommandBar objStandardBar;
Microsoft.Office.Core.CommandBarButton btnCombine;

Microsoft.Office.Interop.Outlook._Inspector olInspector = inspector as Microsoft.Office.Interop.Outlook._Inspector;
object item = olInspector.CurrentItem;
if (item is Outlook._MailItem)
{
Microsoft.Office.Interop.Outlook._MailItem mailItem = item as Microsoft.Office.Interop.Outlook._MailItem;
if (mailItem.To == null && !mailItem.Sent)
{
// this is a new mail
try
{
objStandardBar = olInspector.CommandBars["Standard"];
btnCombine = objStandardBar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing,
"My Unique Button", true, true) as Microsoft.Office.Core.CommandBarButton;
if (btnCombine == null)
{
btnCombine = objStandardBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing,
Type.Missing, Type.Missing, true) as Microsoft.Office.Core.CommandBarButton;
btnCombine.Caption = "My Button";
btnCombine.Tag = "My Unique Button";
}
}
catch(System.Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message, e.Source);
}
}
Marshal.ReleaseComObject(item);
}
}
Posted 02 Nov, 2004 16:31:46 Top
Eugene Starostin


Guest


Hi Ganesh,

It seems to be Sergey's mistake. We have added event wrappers Sergey described to one of http://www.add-in-express.com/news-premium.php. And the code will work with these builds only :-)

You need a solution that is not related to our Add-in Express as you do not use it, am I right?

Posted 02 Nov, 2004 17:08:33 Top
Ganesh Agrawal




Posts: 8
Joined: 2004-11-01
I want a way to achieve this with or without Add-in express.
First I want to get hold of the Create New Message Event in Outlook 2003.

Second I want to add a Command Bar Buton to the New Message Inspector Window.

Any help is appreciated.
Posted 02 Nov, 2004 18:01:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Ganesh,

Starting with ADX version 2.1(Build 1744) the ADX AddinModule has the OlNewInspector event handler. In order to handle the Create New Message Event in Outlook 2003, you need to get the OlNewInspector event from ADX addin module. A new message will have the value of the field "To" = null and "Sent" property = false. See the string "if (mailItem.To == null && !mailItem.Sent)" in my code.
Posted 03 Nov, 2004 07:23:00 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Ganesh,

Second I want to add a Command Bar Buton to the New Message Inspector Window.


There is no need to add your button manually. You can do this with the ADXOlInspectorCommandBar component. When opening a New Message your button will be enabled, in other cases - disabled. See the code below. I would also advice you to set the Temporary property of ADXOlInspectorCommandBar to true.

private void AddinModule_OlNewInspector(object sender, object inspector, string folderName)
{
Outlook._Inspector olInspector = inspector as Outlook._Inspector;
object item = olInspector.CurrentItem;
if (item is Outlook._MailItem)
{
Outlook._MailItem mailItem = item as Outlook._MailItem;
if (mailItem.To == null && !mailItem.Sent)
adxMyButton.Enabled = true;
else
adxMyButton.Enabled = false;
Marshal.ReleaseComObject(item);
}
}
Posted 03 Nov, 2004 07:49:37 Top