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.