Adding a picture to outlook commandbar button

Adding a picture to outlook commandbar button

Post by Exchner » Sat, 08 Nov 2008 02:03:29


Hi,

I have a COM addin (using C++/ATL) and would like to add an icon to
the button. Can anyone help me with some code on how to do this?

Thanks
 
 
 

Adding a picture to outlook commandbar button

Post by cainrando » Sat, 08 Nov 2008 02:20:29


What's the minimum version of Outlook you need to support?

 
 
 

Adding a picture to outlook commandbar button

Post by Exchner » Sat, 08 Nov 2008 02:23:49


Outlook 2003
 
 
 

Adding a picture to outlook commandbar button

Post by cainrando » Sat, 08 Nov 2008 03:22:49


This will actually work if you have Outlook XP and above but compiled
against an earlier version of the Msoutl.olb. If you don't have to
worry about that, replace my GetIDsOfNames stuff with the wrapper
functions.

Using an HBITMAP and an Office::_CommandBarButton:

LPOLESTR propertyName = L"Picture";
DISPID dispId = 0;
HRESULT hr = pCommandBarButton->GetIDsOfNames( IID_NULL,
&propertyName, 1, LOCALE_USER_DEFAULT, &dispId);
if( !FAILED( hr))
{
PICTDESC pictdesc;
memset( &pictdesc, 0, sizeof( PICTDESC));
pictdesc.cbSizeofstruct = sizeof( PICTDESC);
pictdesc.picType = PICTYPE_BITMAP;
pictdesc.bmp.hbitmap = hBitmap;

IPictureDisp *pd = NULL;
hr = OleCreatePictureIndirect( &pictdesc, IID_IPicture, TRUE,
(void**) &pd);
if( !FAILED( hr))
{
VARIANT p1;
p1.vt = VT_DISPATCH;
p1.pdispVal = pd;

DISPPARAMS dp;
DISPID dispidNamed = DISPID_PROPERTYPUT;
dp.rgvarg = &p1;
dp.rgdispidNamedArgs = &dispidNamed;
dp.cArgs = 1;
dp.cNamedArgs = 1;

hr = pCommandBarButton->Invoke( dispId, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF |
DISPATCH_METHOD, &dp, NULL, NULL, NULL);
pd->Release();
}
}
 
 
 

Adding a picture to outlook commandbar button

Post by Exchner » Sun, 09 Nov 2008 01:42:17


I've been trying the same and here is my code -

HANDLE hBmp = ::LoadImage(g_hInstance,

MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),LR_LOADMAP3DCOLORS);

PICTDESC pictdesc;
memset( &pictdesc, 0, sizeof( PICTDESC));
pictdesc.cbSizeofstruct = sizeof( PICTDESC);
pictdesc.picType = PICTYPE_BITMAP;
pictdesc.bmp.hbitmap = (HBITMAP)hBmp;

IPictureDisp *pd = NULL;
hRes = OleCreatePictureIndirect( &pictdesc, IID_IPicture, TRUE,
(void**) &pd);
hRes = spCmdButton->put_Picture(pd);
hRes = spCmdButton->PasteFace();
However, I do not see any image on the button. I've verified that hBmp
is a valid handle and the last 3 hRes return S_OK. Any ideas??
 
 
 

Adding a picture to outlook commandbar button

Post by Exchner » Sun, 09 Nov 2008 01:52:38

n Nov 7, 11:42燼m, Exchnerd < XXXX@XXXXX.COM > wrote:

I forgot to put the style for the button. It now works!! Thanks