Toxter

Hello everyone,
I'm having difficulties with adding a button on toolbar in Outlook 2003 from my addin (C++).
It all works well when I try to add a toolbar and button on 'Main' Outlook window.
I'm doing it like this:

Code Snippet

CComPtr < Office::_CommandBars> spCmdBars; 
CComPtr < Office::CommandBar> spCmdBar;

// QI() for _Application
CComQIPtr <Outlook::_Application> spApp(Application);
ATLASSERT(spApp);
// get the CommandBars interface that represents Outlook's
//toolbars & menu items

CComPtr<Outlook::_Explorer> spExplorer;
spApp->ActiveExplorer(&spExplorer);

HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);

// now we add a new toolband to Outlook
// to which we'll add 2 buttons
CComVariant vName("OutlookAddin");
CComPtr <Office::CommandBar> spNewCmdBar;

// position it below all toolbands
//MsoBarPosition::msoBarTop = 1
CComVariant vPos(1);

CComVariant vTemp(VARIANT_TRUE); // menu is temporary
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
//Add a new toolband through Add method
// vMenuTemp holds an unspecified parameter
//spNewCmdBar points to the newly created toolband
spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);

//now get the toolband's CommandBarControls
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;
CComPtr < Office::CommandBarControl> spNewBar2;

// add first button
spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow);
ATLASSERT(spNewBar);


What I'm trying to do is to add a toolbar with a button on window which is opened when you
click on File->New->Contact.
That window has 'Save and Close' button on toolbar. I'm trying to add my button just before
that 'Save and Close' button.
My problem is that I can't find that toolbar in Outlook object model Sad

Can anyone help me with this please How can I find that toolbar


Re: Visual Studio Tools for Office How to add button to Outlook toolbar?

X4U

Hello Toxter,

that Window is of type Inspector.

All Menus ans ToolBars are called CommandBars.

Within an Inspector the ToolBar's name is "Standard" and the Menu's name is "Menu Bar"

So you can get the CommandBar with ActiveInspector().CommandBars("Standard")

I'm a C# coder - so C++ is not my native - but I'm sure you will know how to translate this.

If you have questions in general to the Outlook Object Model I highly recommend Sue Moshers site

www.outlookcode.com

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office How to add button to Outlook toolbar?

Toxter

Hello X4U,

Thank you for your reply.

When I try to get ActiveInspector() I got NULL, meaning that there is no active Inspector.

While, when I try to get ActiveExprorer() I got one successfuly.

I'm doing this in OnStartupComplete() function.

Any other suggestions please.

Thanks.





Re: Visual Studio Tools for Office How to add button to Outlook toolbar?

X4U

Hello,

this is because there is no active inspector at startup.

You have to trap the Application.Inspectors.NewInspector event.

Usuallly someone would implement a small framework wich I call Explorer/Inspector wrapper.

I can give you only some C# sample code. But you can see the basic technic here.

However - you can have multiple Explorer and Inspector Windows at same time - so you have to keep them watching.

http://www.x4u.de/Outlook/Codesnippets/tabid/61/Default.aspx

I would recommend to study the

X4UTools Explorer/Inspector sample also the OUtlookAdminTools is a good one to start.

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office How to add button to Outlook toolbar?

Toxter

Yes, I had to intercept InpectorEvents.Activate() event.
It works well now.
Thank you for your help, it is most appreciated.