Add an image to a commandbar button

  • Thread starter Thread starter Marc
  • Start date Start date
M

Marc

I'm trying to add an image to a commandbar button. I was using
objButton.Picture to load .BMPs onto the buttons. This works great in
Outlook 2002 and 2003 but the Outlook 2000 model doesn't support this. I
know you can use the copyface and pasteface methods to copy an image from
another button but how do you do this if you don't currently have a
commandbar button with the image you want to use?
Using the Outlook 2000 model is there a way to adding a image to a button
from an imagelist or from a button on a form in the add-in ... or any other
way?

Thanks,
Marc
 
You don't need to call CopyFace on an existing button - copy your own bitmap
to the clipboard, then call PasteFace.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks Dmitry ... I did some playing around last night and figure it out. I
just created a new form in my add-in that contains all of my images and now
I can do the following

Private Sub AddMyCommandBar(objCBs As CommandBars)
Dim objCB As CommandBar
Dim objCBCs As CommandBarControls, objCBC As CommandBarControl

On Error Resume Next

Set objCB = objCBs.Add("MyCommandBar", msoBarTop, , True)
Set objCBCs = objCB.Controls

Set btnOptions = objCBCs.Add(, , , , True)
btnOptions.Caption = "Mailfuse Options"
btnOptions.OnAction = "!<" & msProgID & ">"
btnOptions.Style = msoButtonIconAndCaption
Clipboard.SetData frmImages.imgOptions.Picture, vbCFBitmap
btnOptions.PasteFace
...

Maybe you/someone can answer another question while looking at this code. I
use the above code to add a new commandbar and buttons to the inspector when
a mail item is viewed. I've tested this on a few different OSs and also
different versions of Outlook and things work pretty good. In Outlook 2003
however each time an email is opened it adds the commandbar but the old one
is still there. In Outlook 2000 and 2002 the old commandbar seems to be
removed after the inspector is closed so I don't get duplicates.

How can I check when the inspector opens to see if the commandbar is still
there so I can skip trying to readd it? I tried doing something like
objCBs.FindControl to see if I can find one of my controls but I dont' know
what to put as the ID to search for.
Should I make objCB global istead of creating in the sub so I can check
reference it my moInspectors_NewInspector event?

I know I should realy start a new thread for this question so if I don't get
any responses I'll create a new post.

Thanks,
Marc
 
This is normal: Outlook reuses inspectors, which results in the old custom
toolbars to be there but not hooked up to your event handlers.
Use Inspector.CommandBars.Item("YourToolbarName") to try to access an
existing toolbar. If you don't get an error, simply delete that toolbar,
then add the toolbar again whether it was there before or not.
Also make sure you set the Temporary parameter to true when calling
CommandBars.Add() to make sure your roolbar is not persisted between Outlook
sessions.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top