CommandBarButton Picture Displays Improperly in 2007/B2

M

Michael

My command bar pictures are displaying improperly in Visio 2007 when they
were correct in Visio 2003 and Visio 2002. My C++ code is basically this:

Office::_CommandBarButton* pCmdBarBtn = SomeCommandBarButton;
PICTDESC PictDesc;
PictDesc.cbSizeofstruct = sizeof(PictDesc);
PictDesc.picType = PICTYPE_BITMAP;
HICON hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(nIconResource),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ICONINFO IconInfo;
GetIconInfo(hIcon, &IconInfo);
PictDesc.bmp.hbitmap = IconInfo.hbmColor;
PictDesc.bmp.hpal = NULL;
CComPtr<IPictureDisp> pColor;
OleCreatePictureIndirect(&PictDesc, __uuidof(pColor), TRUE, (void**)&pColor);
pCmdBarBtn->PutPicture(pColor);

CComPtr<IPictureDisp> pMask;
PictDesc.bmp.hbitmap = IconInfo.hbmMask;
PictDesc.bmp.hpal = NULL;
OleCreatePictureIndirect(&PictDesc, __uuidof(pMask), TRUE, (void**)&pMask);
pCmdBarBtn->PutMask(pMask);

The resources are RT_GROUP_ICON type and contain 16x16 16 color icons.
Visio is attempting to render the icons because I can make out the basic
shape but the coloring is incorrect. Am I doing something wrong or has a bug
been introduced here?

BTW my OS is XP Pro/SP2.

Thanks.
 
M

Michael

Actually this is a bug in Visio 2007 Beta 2 that I sure hope is fixed before
the release is out. I suspect custom faces for CommandBarButtons will be
seriously impacted if not. Consider the following VBA code:

Sub CreateHeartButton()
Dim CBB As CommandBarButton, CBS As CommandBars, CB As CommandBar

Set CBS = Application.CommandBars
On Error Resume Next
CBS.Item("My Tool Bar").Delete
On Error GoTo 0
Set CB = CBS.Add("My Tool Bar", , , True)
CB.Visible = True
Set CBB = CB.Controls.Add(msoControlButton)
CBB.Caption = "My Caption"

CBB.FaceID = 481 ' Standard heart button
CBB.Visible = True

Dim FSO, TF As String
Set FSO = CreateObject("Scripting.FileSystemObject")
TF = FSO.getspecialfolder(2)

SavePicture CBB.Picture, TF & "\pic.bmp" ' Save as a bitmap and mask
SavePicture CBB.Mask, TF & "\mask.bmp"

' Now load the standard heart as a picture from the files.
Dim Pic As IPictureDisp, Mask As IPictureDisp
Set Pic = LoadPicture(TF & "\pic.bmp")
Set Mask = LoadPicture(TF & "\mask.bmp")
FSO.deletefile TF & "\pic.bmp"
FSO.deletefile TF & "\mask.bmp"

CBB.Picture = Pic
CBB.Mask = Mask

MsgBox "Notice the picture now and watch it change..."

ThisDocument.Close

End Sub


If you run this macro, it creates a toolbar and adds a button with the
standard heart image. The heart image is distorted when the
ThisDocument.Close method is called. This same distortion occurs if the
picture is created using icons or bitmaps from external sources (e.g.,
OleCreatePictureIndirect in C++) rather than the internal Visio images. I
just wanted to use a standard image for simplicity in the example. Also,
note that other things can be done to distort the image. The Close method is
not the only thing. You can create another document for example and see the
same effect.

I hope I'm reporting this to the proper location to get Visio 2007 problems
fixed before the release is made. Note this was not a problem in earlier
versions of Visio.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top