256 color image buttons for Word add-in?

J

Jerry Nettleton

I'm working on a COM add-in for Word (written in VC++) and would like to use
256 color images for the buttons in the command bar. Does anyone have a
sample of how to load 256 color images? I've looked for a good sample on
the web and haven't found anything yet.

Thanks,
Jerry N.
 
W

Wei-Dong XU [MSFT]

Hi Jerry,

Currently we are finding one support professional for you on this issue. If
any result, we will reply you at the first time.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
It is my pleasure to be of assistance.
 
P

Peter Huang [MSFT]

Hi

Here is KB for VB code.
How To Set the Mask and Picture Properties for Office XP CommandBars
http://support.microsoft.com/default.aspx?scid=kb;en-us;286460

Here is some code snippet in C++ for your reference.

============================================================================
=======
VARIANT vtCommandBars; VariantInit(&vtCommandBars);
VARIANT vtStandardCommandBar; VariantInit(&vtStandardCommandBar);
VARIANT vtControls; VariantInit(&vtControls);
VARIANT vtButton; VariantInit(&vtButton);

HRESULT hr;

VARIANT vtName; VariantInit(&vtName);
VARIANT vtControlButton; VariantInit(&vtControlButton);
VARIANT vtTag; VariantInit(&vtTag);
VARIANT vtVisible; VariantInit(&vtVisible);

vtName.vt = VT_BSTR;
vtName.bstrVal = ::SysAllocString(L"Standard");

vtControlButton.vt = VT_I4;
vtControlButton.lVal = 1;

vtTag.vt = VT_BSTR;
vtTag.bstrVal = ::SysAllocString(L"MyButton");

vtVisible.vt = VT_BOOL;
vtVisible.boolVal = VARIANT_TRUE;

hr = GetProperty(m_pParentApp, L"CommandBars", &vtCommandBars);
hr = CallMethod(vtCommandBars.pdispVal, L"Item", &vtStandardCommandBar,
1,
&vtName);

hr = GetProperty(vtStandardCommandBar.pdispVal, L"Controls", &vtControls);
hr = CallMethod(vtControls.pdispVal, L"Add", &vtButton, 1,
&vtControlButton);

m_pButton = vtButton.pdispVal;
m_pButton->AddRef();

hr = PutProperty(m_pButton, L"Tag", &vtTag);

HBITMAP hbmpCircle = LoadBitmap( g_hModule, (LPCTSTR) IDB_CIRCLE);
HBITMAP hbmpMask = LoadBitmap( g_hModule, (LPCTSTR) IDB_MASK);

PICTDESC pdesc;
pdesc.cbSizeofstruct = sizeof (pdesc);
pdesc.picType = PICTYPE_BITMAP;
pdesc.bmp.hbitmap = hbmpCircle;

IPictureDisp* pPictureDispCircle;
hr = ::OleCreatePictureIndirect(&pdesc, IID_IPictureDisp, FALSE,
(LPVOID*)&pPictureDispCircle);

if (SUCCEEDED(hr))
{
VARIANT vtCircle;VariantInit(&vtCircle);

vtCircle.vt = VT_DISPATCH;
vtCircle.pdispVal = pPictureDispCircle;
vtCircle.pdispVal->AddRef();

hr = PutProperty(m_pButton, L"Picture", &vtCircle);

VariantClear(&vtCircle);
pPictureDispCircle->Release();
}

pdesc.cbSizeofstruct = sizeof (pdesc);
pdesc.picType = PICTYPE_BITMAP;
pdesc.bmp.hbitmap = hbmpMask;

IPictureDisp* pPictureDispMask;
hr = ::OleCreatePictureIndirect(&pdesc, IID_IPictureDisp, FALSE,
(LPVOID*)&pPictureDispMask);

if (SUCCEEDED(hr))
{
VARIANT vtMask;VariantInit(&vtMask);

vtMask.vt = VT_DISPATCH;
vtMask.pdispVal = pPictureDispMask;
vtMask.pdispVal->AddRef();

hr = PutProperty(m_pButton, L"Mask", &vtMask);

VariantClear(&vtMask);
pPictureDispMask->Release();
}

hr = PutProperty(m_pButton, L"Visible", &vtVisible);

DeleteObject(hbmpCircle);
DeleteObject(hbmpMask);

VariantClear(&vtVisible);
VariantClear(&vtTag);
VariantClear(&vtName);
VariantClear(&vtControlButton);

VariantClear(&vtButton);
VariantClear(&vtControls);
VariantClear(&vtCommandBars);
VariantClear(&vtStandardCommandBar);
============================================================================
=======

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jerry N

I don't think this approach will work for me. I need to be compatible with
Office 2000 and the new Picture and Mask properteries appear to be new for
Office XP. I've been struggling with LoadImage() and I think I need to
create a palette. I wasn't sure how to copy everything that I need into the
clipboard before calling PasteFace().

Thanks,
Jerry
 
P

Peter Huang [MSFT]

Hi

Here are article which will use PasteFace approach.

How To Place a Custom Bitmap on an Office Commandbar Button (198522)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;198522

The article will use VB6, but it main call the API to do the job.
How To Create a Transparent Picture For Office CommandBar Buttons (288771)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;288771

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

That article is a good one but there's one little quirk. If you store your
image in a resource file and load it using LoadPicture you'll find that
sometimes even if your BMP image is 256 colors to comply with the Office
button specs that VB will load it to the clipboard as an IPicture with more
colors and that the mask color you select, for example magenta, will show up
as the background color and not as a transparent color. It's an intermittent
thing so you might see it only once in a hundred times.
 
Y

Yan-Hong Huang[MSFT]

Hello Jerry,

I am reviewing the issue thread. Do you have any more concerns on this
problem? If there is any unclear, please feel free to post here and our
engineer will follow up.

By the way, please use (e-mail address removed) to post your questions
since that is your valid registered no spam alias. If you change to another
email alias, you may not receive timely response unless you register it
again.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

ssissa

Hi,

I have found article 288771 useful for creating pictures with transparency
for CommandBar buttons in Office versions prior to XP. However, I have found
that this solution only works on English systems.

I suppose the problem is caused by the clipboard format strings "Toolbar
Button Face" and "Toolbar Button Mask" coded in the solution. Is there an
easy way to get the correct strings based on the system localization? For
example, is there a constant or variable exposed somewhere that will contain
the correct strings? Or is there another solution to creating these
transparent pictures for non-XP Office versions that works regardless of
system localization?

Thanks,
Bret
 
P

Peter Huang [MSFT]

Hi

Based on my test, it seems to work at my side when the locale is set to
Chinese PRC other than english. And I did not find such a list about
different language.
Also RegisterClipboardFormat with a string will return a Long value to
identify the Format ID,
Based on my test, it is as below.
49981 Toolbar Button Face
49982 Toolbar Button Mask

Firstly you may try to dump the value after you call RegisterClipboardFormat
e.g.
' Get the cf for button face and mask.
cfBtnFace = RegisterClipboardFormat("Toolbar Button Face")
Debug.Print cfBtnFace
cfBtnMask = RegisterClipboardFormat("Toolbar Button Mask")
Debug.Print cfBtnMask

to see if it is 49981 and 49982.
Also you may try to use cfBtnFace and cfBtnMask directly by setting the
cfBtnFace to 49981 and cfBtnMask to 49982 to see if that works.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

ssissa

Hi,

The results of calls to RegisterClipboardFormat are different for me even on
platforms where there is no problem. Moreover, it seems the function returns
different values each time after restarting Windows. Hence, I am lead to
believe that these values cannot be treated as constants.

Setting cfBtnFace and cfBtnMask to the constant values you indicated, or any
random values, results in the same behavior that I observe on non-English
systems. This strengthens my supposition that the problem has something to do
with the strings passed to RegisterClipboardFormat not matching the values
expect by Office.

I have found a similar diagnosis related to the clipboard format names on
other newsgroups, but without a well defined solution:
http://www.dotnetmonster.com/Uwe/Forum.aspx/vs-net-ide/1846/creating-popup-menu

I have observed the incorrect behavior on French and Greek systems, where
both Windows and Office are associated versions. These are the only language
platforms I have tested thus far, although the link above relates to German
as well.

Thanks,
Bret
 
P

Peter Huang [MSFT]

Hi

Thanks for your feedback, so far I am trying to see if I can find some
document about the string on other language platform.
Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hello,

Based on my further troubleshooting, You are correct in understanding that
the string accepted by RegisterClipboardFormat is locale specific and that¡
¯s the reason why it may not be working on non-english locale.

We can find the string used in a specific locale by using Word to copy a
command bar button image and look at the clip board format it uses in that
specific locale.
The exact steps for doing this are:
1) Open Word and right click on the toolbar and click Customize
2) Add a new toolbar
3) Drag a command item (from the commands tab) which has an icon on it.
4) With the Customize dialog open, Select the icon on the toolbar and
select ¡°Copy button image¡± (This is so that Word will send the Face and
Mask clipboard formats to clipboard.)

Now using a clipboard viewer you can view what are the strings used for the
Face and Mask clipboard formats.
If you have Visual Studio 6 installed then you can find ¡°DataObject Viewer¡
± tool under Programs->Visual Studio 6-> Visual Studio 6 tools.

You will get the string to be used from this. You will need to do this
process on all the locales that you are targeting your application at. You
can keep these strings in your applications string table so that depending
on the locale you choose the appropriate clipboard format string.

Unfortunately, there is no way this can be done at run time. Also there is
no locale independent clipboard format string which could be passed to
RegisterClipboardFormat.

Considering this Office XP onwards expose two additional properties Mask
and Face for CommandBarButton object.

If you are targeting for Office versions of Office XP onwards you can this
approach. Here is a knowledge base article on this:

How To Set the Mask and Picture Properties for Office XP CommandBars
http://support.microsoft.com/kb/286460/

Please let me know if this information is useful or if you have any
additional queries on this.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

chetan

Hi Jerry Nettleton,

I am also facing same problem.

Did you find any solution for this? If yes please tell us how to se
icon/image on toolbar button in Office 2000.

Chetan Shind
 

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