C++
  Home arrow C++ arrow Page 5 - Building An Outlook COM Add-In With VC /A...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Building An Outlook COM Add-In With VC /ATL
By: Amit Dey
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 55
    2002-02-17

    Table of Contents:
  • Building An Outlook COM Add-In With VC /ATL
  • Getting started
  • Building a minimal COM add-in
  • Command and conquer
  • Command and conquer (contd.)
  • Lord of the (disp) sinks
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

    //......

    //code to add toolbar here

    //......

    _bstr_t bstrNewMenuText(OLESTR("New Menu Item"));

    CComPtr < Office::CommandBarControls> spCmdCtrls;

    CComPtr < Office::CommandBarControls> spCmdBarCtrls;

    CComPtr < Office::CommandBarPopup> spCmdPopup;

    CComPtr < Office::CommandBarControl> spCmdCtrl;

    // get CommandBar that is Outlook's main menu

    hr = spCmdBars->get_ActiveMenuBar(&spCmdBar);

    if (FAILED(hr))

    return hr;

    // get menu as CommandBarControls

    spCmdCtrls = spCmdBar->GetControls();

    ATLASSERT(spCmdCtrls);

    // we want to add a menu entry to Outlook's 6th(Tools) menu //item

    CComVariant vItem(5);

    spCmdCtrl= spCmdCtrls->GetItem(vItem);

    ATLASSERT(spCmdCtrl);



    IDispatchPtr spDisp;

    spDisp = spCmdCtrl->GetControl();



    // a CommandBarPopup interface is the actual menu item

    CComQIPtr < Office::CommandBarPopup> ppCmdPopup(spDisp);

    ATLASSERT(ppCmdPopup);



    spCmdBarCtrls = ppCmdPopup->GetControls();

    ATLASSERT(spCmdBarCtrls);



    CComVariant vMenuType(1); // type of control - menu

    CComVariant vMenuPos(6);

    CComVariant vMenuEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

    CComVariant vMenuShow(VARIANT_TRUE); // menu should be visible

    CComVariant vMenuTemp(VARIANT_TRUE); // menu is temporary





    CComPtr < Office::CommandBarControl> spNewMenu;

    // now create the actual menu item and add it

    spNewMenu = spCmdBarCtrls->Add(vMenuType, vMenuEmpty, vMenuEmpty, vMenuEmpty, vMenuTemp);

    ATLASSERT(spNewMenu);



    spNewMenu->PutCaption(bstrNewMenuText);

    spNewMenu->PutEnabled(VARIANT_TRUE);

    spNewMenu->PutVisible(VARIANT_TRUE);



    //we'd like our new menu item to look cool and display

    // an icon. Get menu item as a CommandBarButton

    CComQIPtr < Office::_CommandBarButton> spCmdMenuButton(spNewMenu);

    ATLASSERT(spCmdMenuButton);

    spCmdMenuButton->PutStyle(Office::msoButtonIconAndCaption);



    // 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().

    spCmdMenuButton->PasteFace();

    // show the menu

    spNewMenu->PutVisible(VARIANT_TRUE);

    return S_OK;

    }


    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.

    Our tool bar items in action

    Our popup menu items in action

    More C++ Articles
    More By Amit Dey


     

    C++ ARTICLES

    - Paths and Files
    - Directories in C++
    - Focusing on C++ Files
    - Const Correctness in C++
    - Manipulating Streams and Files with C++
    - Streams and Files
    - Multiplying Large Numbers with Karatsuba`s A...
    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT