One of the great things about Windows is the ability that we have to create COM-based add-in's for the entire suit of Office 2000 applications. In this article, Amit shows us how to create an Outlook 2000 COM add-in using a pure Visual C ATL COM object. He starts by writing a basic functional COM add-in, and then adds standard user interface elements such as toolbars and menu items to Outlook. He finishes up by showing us how to respond to their events.
Building An Outlook COM Add-In With VC /ATL - Command and conquer (contd.) (Page 5 of 7 )
The ActiveMenuBar property of the CommandBars collection returns a CommandBar object that represents the active menu bar in the container application (i.e. Outlook 2000 for our example). Next, we query for the active menubar's controls collection (CommandBarControls) through the GetControls method. Since we want to add a popup menu item to Outlook's tools (6th position) menu, we retrieve the 6th item in the ActiveMenuBars control collection and call its add method to create a new menu item which is attached to the tools menu.
Here's the code snippet to accomplish everything we have just discussed:
// we want to use the same toolbar bitmap for menuitem too.
// we grab the CommandBarButton interface so we can add
// a bitmap to it through PasteFace().
// show the menu
With that under our belt, it's F5 time. If everything has gone OK, the project builds successfully and you are about to get a first glimpse of our add-in in action. Since we are going to run outlook to test our add-in, in the "Executable for Debug" dialog, browse to the current path for the outlook executable (outlook.exe). In outlook, go to the Tools->Options menu, and under the other tab, click advanced options. From the advanced options dialog, click on the COM add-ins button. Next, check the entry for our add-in in the add-ins available list box and click OK. As our add-in is loaded by outlook, a new docked toolband with two buttons is created. Take a look at the cool looking menu item that we've just added to outlook's Tools menu.