How to add a CommandBar and buttons in Outlook 2003 mail window?
Locked
How to add a CommandBar and buttons in Outlook 2003 mail window?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Edited byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:46 PM
- Edited byJi.ZhouMSFT, ModeratorSaturday, February 14, 2009 1:09 AM
Answers
Outlook application has two types of UI windows: Explorer Window and Inspector Window. The main UI window is an explorer, and the mail/contact/appointment/meeting item window is the inspector type. We can add a command bar into the explorer window easily by calling this.Application.ActiveExplorer().CommandBars.Add(…).
But in order to add a command bar and buttons into the inspector window, we need to listen to Application.Inspectors.NewInspector event. This event fires whenever a new inspector is created and shown. In the handler function, we receive an instance of inspector object from the parameter. Then we can call Inspector.CommandBars.Add(…) to create the command bar.
The codes look like:
Outlook.Inspectors inspectors = null;
Office.CommandBar cb;
Office.CommandBarComboBox edt;
Office.CommandBarButton btn;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
}
void inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
cb = Inspector.CommandBars.Add("test", Office.MsoBarPosition.msoBarTop,
false, true) as Office.CommandBar;
cb.Visible = true;
cb.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize;
edt = cb.Controls.Add(Office.MsoControlType.msoControlEdit, missing, missing, missing, true) as Office.CommandBarComboBox;
edt.Caption = "My Editor";
edt.Tag = "My Editor";
btn = cb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton;
btn.Caption = "My Button";
btn.Tag = "My Button";
}
(Related forum thread, http://social.msdn.microsoft.com/forums/en-US/vsto/thread/4ca19753-9883-4a86-a825-36de4e3ba941/ )
For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:46 PM
All Replies
Outlook application has two types of UI windows: Explorer Window and Inspector Window. The main UI window is an explorer, and the mail/contact/appointment/meeting item window is the inspector type. We can add a command bar into the explorer window easily by calling this.Application.ActiveExplorer().CommandBars.Add(…).
But in order to add a command bar and buttons into the inspector window, we need to listen to Application.Inspectors.NewInspector event. This event fires whenever a new inspector is created and shown. In the handler function, we receive an instance of inspector object from the parameter. Then we can call Inspector.CommandBars.Add(…) to create the command bar.
The codes look like:
Outlook.Inspectors inspectors = null;
Office.CommandBar cb;
Office.CommandBarComboBox edt;
Office.CommandBarButton btn;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
}
void inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
cb = Inspector.CommandBars.Add("test", Office.MsoBarPosition.msoBarTop,
false, true) as Office.CommandBar;
cb.Visible = true;
cb.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize;
edt = cb.Controls.Add(Office.MsoControlType.msoControlEdit, missing, missing, missing, true) as Office.CommandBarComboBox;
edt.Caption = "My Editor";
edt.Tag = "My Editor";
btn = cb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton;
btn.Caption = "My Button";
btn.Tag = "My Button";
}
(Related forum thread, http://social.msdn.microsoft.com/forums/en-US/vsto/thread/4ca19753-9883-4a86-a825-36de4e3ba941/ )
For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:46 PM
Add VB version codes,
public class ThisAddIn
Dim inspectors As Outlook.Inspectors
Dim cb As Office.CommandBar
Dim edt As Office.CommandBarComboBox
Dim btn As Office.CommandBarButton
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
inspectors = Application.Inspectors
AddHandler inspectors.NewInspector, AddressOf inspectors_NewInspector
End SubSub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector)
cb = Inspector.CommandBars.Add("test", Office.MsoBarPosition.msoBarTop, False, True)
cb.Visible = True
cb.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize
edt = cb.Controls.Add(Office.MsoControlType.msoControlEdit, , , , True)
edt.Caption = "My Editor"
edt.Tag = "My Editor"
btn = cb.Controls.Add(Office.MsoControlType.msoControlButton, , , , True)
btn.Caption = "My Button"
btn.Tag = "My Button"
End Sub
End Class
We have published a VSTO FAQ recently, you can view them from the entry thread http://social.msdn.microsoft.com/Forums/en/vsto/thread/31b1ffbf-117b-4e8f-ad38-71614437df59. If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.


