Click here to Skip to main content
11,644,731 members (67,183 online)
Click here to Skip to main content

Adding a new Toolbar and Button to Microsoft Outlook Tutorial - 1

, 22 May 2004 CPOL 137.3K 1K 46
Rate this:
Please Sign up or sign in to vote.
This project aims at adding a new toolbar and button to Microsoft Outlook

Introduction

  1. Select new ATL COM Wizard - and then select DLL Project.
  2. Add an ATL Object through Wizard.
  3. Implement Interface -> Add Type Lib -> Microsoft Add-in Designer -> _IDTExtensibility2.
  4. Add Outlook architecture and Outlook library in stdafx.h. This changes according to your system configuration where you have installed Office.

    This is pertaining to Microsoft Office XP:

    #import "C:\Program Files\Common Files\Microsoft 
      Shared\Office10\mso.dll" rename_namespace("Office"), 
      named_guids using namespace Office; 
    #import "D:\Program Files\Microsoft Office\Office10\MSOUTL.olb" 
      rename_namespace("Outlook"), named_guids, 
      raw_interfaces_only using namespace Outlook;

    For Office 2000:

    #import "D:\Program Files\Microsoft Office\Office\mso9.dll" 
      rename_namespace("Office"), named_guids using namespace Office; 
    #import "D:\Program Files\Microsoft Office\Office\MSOUTL9.olb" 
      rename_namespace("Outlook"), named_guids, 
      raw_interfaces_only using namespace Outlook;
  5. Add Registry entry in Addin.rgs.
    HKCU
    {
    Software
    {
    Microsoft
    {
    Office
    {
    Outlook
    {
    Addins
    {
    'MyAddin.Addin'
    {
    val FriendlyName = s 'My Outlook Addin'
    val Description = s 'Outlook Addin'
    val LoadBehavior = d '00000016'
    val CommandLineSafe = d '00000000' 
    }
    }
    }
    }
    }
    }
    }
  6. Add member variables in Addin.h.
  7. Add the following code in Addin.h's OnConnection method:
    STDMETHOD(OnConnection)(IDispatch * Application, 
        ext_ConnectMode ConnectMode, IDispatch * AddInInst, 
        SAFEARRAY * * custom)
    {
    // QueryInterface() for _Application
    CComQIPtr <Outlook::_Application> spApp(Application); 
    ATLASSERT(spApp);
    
    //make a copy of our Application Object
    m_spApp = spApp;
    
    //get the ActiveExplorer Object
    //each window is called as an Explorer in Outlook
    //so our current viewing wimdow when Outlook starts is Explorer
    //so get the object
    spApp->ActiveExplorer(&spExplorer);
    
    
    // get the CommandBars interface that represents Outlook's
    // toolbars & menu items 
    HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
    if(FAILED(hr))
    return hr;
    ATLASSERT(spCmdBars);
    
    //give a name for our newly created Toolbar
    CComVariant vName("MyAddin Toolbar");
    //obtain a reference to CommandBar Control
    CComPtr <Office::CommandBar> spNewCmdBar;
    //sepcify in which position our button to be placed.
    //for us it is 1st position
    CComVariant vPos(1); 
    CComVariant vTemp(VARIANT_TRUE); 
    CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR); 
    
    //add the toolbar 
    spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
    
    //to add a button to our toolbar we have to get a reference
    //to CommandBarControls Control.Consider Button as a Command
    //BarControl.For Further details,refer Microsoft Outlook
    //Object Model.
    CComPtr < Office::CommandBarControls> spBarControls;
    spBarControls = spNewCmdBar->GetControls();
    ATLASSERT(spBarControls);
    //MsoControlType::msoControlButton = 1
    CComVariant vToolBarType(1);
    //show the toolbar
    CComVariant vShow(VARIANT_TRUE);
    CComPtr < Office::CommandBarControl> spNewBar; 
    //now add the CommandBarControls of type Button 
    spNewBar = spBarControls->Add(vToolBarType, 
                     vEmpty, vEmpty, vEmpty, vShow); 
    ATLASSERT(spNewBar);
    
    _bstr_t bstrNewCaption(OLESTR("Item1"));
    _bstr_t bstrTipText(OLESTR("Tooltip for Item1"));
    //now comes the work of adding the Button to our CommandBarControl
    //get a reference to CommandBarButton
    CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
    ATLASSERT(spCmdButton);
    
    //assign the properties
    spCmdButton->PutVisible(VARIANT_TRUE); 
    spCmdButton->PutCaption(OLESTR("MyButton")); 
    spCmdButton->PutEnabled(VARIANT_TRUE);
    spCmdButton->PutTooltipText(OLESTR("Tooltip for MyButton")); 
    spCmdButton->PutTag(OLESTR("Tag for MyButton")); 
    
    //put into picture the New CommandBarControl too
    spNewCmdBar->PutVisible(VARIANT_TRUE); 
    
    m_spButton = spCmdButton;
    
    return E_NOTIMPL;
    }
  8. Save and compile the Project.

That's it!!!!...... You have successfully added a new Toolbar with a new Button placed in it!!!!!

Congrats....your first step in Add-in tutorial is over!!!!!!!!

How To See My Add-in???

--->Open Outlook Express. Since in Registry Settings, for Load Behavior we have specified 00000016, this loads our add-in at startup of Outlook Express each time. The other load behaviors are as follows:

  • 00000008 - Load By Demand.
  • 00000003 - Load at Startup only once.

--->I request all the users to use 00000016 because it can relieve confusion of how to load an add-in.

If Add-in not loaded...then how to load???

--->The work is simple....Open Outlook Express... choose Tools....Options.... you will get a tab, choose 'other' options from the tab... and then choose 'Advanced Options'... and then 'COM Add-ins'...you will now see your registered add-ins list... choose your add-in and press OK.

So your first task of adding a Button is over...soon you will have the code for responding to the Button Click produced to you.....

Please feel free to send your reviews to chakkaradeepcc@yahoo.com.

Credits:

  1. This tutorial was based on the idea of Amit Dey in his tutorial, Building an Office2K COM add-in with VC++/ATL.

    So all my thanks goes to Mr.Amit Dey who was 'the guru' for me to Add-ins.

  2. And I mention Igor Tandek of Microsoft Corporation for his great help in making me understand the Inner Concepts of Add-ins along with ATL COM.

A small request to Amit Dey....any contact number or address or mail-id?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

chakkaradeepcc
Software Developer
New Zealand New Zealand
Chakkaradeep, known as Chaks to his friends, hails from the Indian subcontinent.Having done his Masters in Software Engineering, he knows his way around a computer and has sound knowledge of Microsoft technologies.

Chaks is currently working as a Microsoft Developer @ New Zealand.

You can reach him via his blog - http://chakkaradeep.wordpress.com

You may also be interested in...

Comments and Discussions

 
GeneralPlugin is not loaded for other MS Outlook 2000 instance Pin
sunil_200810-Aug-09 21:08
membersunil_200810-Aug-09 21:08 
GeneralControls ID Pin
sunil_20088-Aug-09 2:57
membersunil_20088-Aug-09 2:57 
GeneralOnDisconnection is not called for MS Outlook of office 2000 Pin
sunil_20088-Aug-09 2:33
membersunil_20088-Aug-09 2:33 
GeneralOutlook plugin is not loaded on vista Pin
sunil_20088-Aug-09 2:13
membersunil_20088-Aug-09 2:13 
QuestionLoad Behavior 16 or 3 Pin
xubutian26-Jan-09 13:32
memberxubutian26-Jan-09 13:32 
GeneralButtons not visible in OUTLOOK Pin
sumeetpk29-Nov-06 20:02
membersumeetpk29-Nov-06 20:02 
GeneralRe: Buttons not visible in OUTLOOK Pin
Digambar Borse21-Jan-07 18:17
memberDigambar Borse21-Jan-07 18:17 
QuestionRe: Buttons not visible in OUTLOOK Pin
srinivasan balaji8-May-07 23:03
membersrinivasan balaji8-May-07 23:03 
GeneralMicrosoft Outlook or Outlook Express Pin
Hakuna-Matada14-Jul-06 19:03
memberHakuna-Matada14-Jul-06 19:03 
QuestionHow to handle LButtonEvent? Pin
xdeveloper_del29-May-06 21:24
memberxdeveloper_del29-May-06 21:24 
QuestionHow to add a menu Item in File|New menu with C++?? Pin
mnislamshihan27-Aug-05 6:02
membermnislamshihan27-Aug-05 6:02 
General2 Bug 1)several Explorer 2) automation Pin
guillaume alcalay30-Jun-05 5:23
memberguillaume alcalay30-Jun-05 5:23 
GeneralRe: 2 Bug 1)several Explorer 2) automation Pin
srinivasan balaji24-May-07 1:54
membersrinivasan balaji24-May-07 1:54 
GeneralRe: 2 Bug 1)several Explorer 2) automation Pin
guillaume alcalay25-May-07 1:30
memberguillaume alcalay25-May-07 1:30 
GeneralToolbarbutton position Pin
Josef Jilch28-Apr-05 1:54
sussJosef Jilch28-Apr-05 1:54 
GeneralLink Error Pin
Koundinya29-Mar-05 23:18
memberKoundinya29-Mar-05 23:18 
GeneralRe: Link Error Pin
guillaume alcalay30-Jun-05 4:50
memberguillaume alcalay30-Jun-05 4:50 
GeneralRe: Link Error Pin
ZarTech19-Mar-08 16:07
memberZarTech19-Mar-08 16:07 
GeneralCOM Addin Plugin for all Outlook versions Pin
JLxDev16-Nov-04 9:51
sussJLxDev16-Nov-04 9:51 
GeneralRe: COM Addin Plugin for all Outlook versions Pin
poortl910927-Apr-05 14:05
memberpoortl910927-Apr-05 14:05 
GeneralRe: COM Addin Plugin for all Outlook versions Pin
jswoofer1-Oct-06 11:32
memberjswoofer1-Oct-06 11:32 
GeneralLink error Pin
savages24-Jun-04 1:33
membersavages24-Jun-04 1:33 
GeneralRe: Link error Pin
excaliburger9-Nov-04 3:21
memberexcaliburger9-Nov-04 3:21 
GeneralRegarding the low rating Pin
Gilad Novik23-May-04 4:37
memberGilad Novik23-May-04 4:37 
GeneralRe: Regarding the low rating Pin
Anonymous24-Jun-04 16:47
sussAnonymous24-Jun-04 16:47 
GeneralI didn't know you could do OE plugins Pin
Jason De Arte18-May-04 13:56
memberJason De Arte18-May-04 13:56 
GeneralImages not displaying Pin
Dan Colasanti18-May-04 11:47
memberDan Colasanti18-May-04 11:47 
GeneralRe: Images not displaying Pin
chakkaradeepcc19-May-04 8:24
memberchakkaradeepcc19-May-04 8:24 
GeneralRe: Images not displaying Pin
Dan Colasanti19-May-04 9:44
memberDan Colasanti19-May-04 9:44 
Questionexpress? Pin
Paolo Messina18-May-04 9:37
memberPaolo Messina18-May-04 9:37 
AnswerRe: express? Pin
Dandy Cheung18-May-04 20:25
memberDandy Cheung18-May-04 20:25 
GeneralRe: express? Pin
Paolo Messina19-May-04 3:00
memberPaolo Messina19-May-04 3:00 
AnswerRe: express? Pin
chakkaradeepcc19-May-04 7:57
susschakkaradeepcc19-May-04 7:57 
GeneralRe: express? Pin
Jason De Arte20-May-04 13:30
memberJason De Arte20-May-04 13:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 23 May 2004
Article Copyright 2004 by chakkaradeepcc
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid