Alun Jones
2007-07-27 18:06:40 UTC
As part of an Outlook add-in, I'm trying to put my own image into a
CommandBarButton.
The usual technique I've seen listed is to open the clipboard, empty it,
fill it with the bitmap, then call PasteFace on the button.
Obviously, this is less than desirable, because it wipes out the content of
the clipboard.
I'm trying to use put_Picture, but can't get it to work. If you've had
success with this, please let me know, otherwise perhaps you could look at
the code below and tell me if I'm doing anything obviously wrong:
HBITMAP hBmp = LoadBitmap((HINSTANCE)gInstance,
MAKEINTRESOURCE(IDB_BITMAP1));
HRESULT hr;
CComPtr<IPicture> pPicture;
PICTDESC pd;
ZeroMemory(&pd,sizeof pd);
pd.cbSizeofstruct = sizeof pd;
pd.picType = PICTYPE_BITMAP;
pd.bmp.hbitmap = hBmp;
pd.bmp.hpal = 0;
hr = OleCreatePictureIndirect( &pd,
__uuidof(pPicture),
FALSE,
(LPVOID *)&pPicture );
if (FAILED(hr))
return hr;
OLE_XSIZE_HIMETRIC nWidth = 0;
OLE_YSIZE_HIMETRIC nHeight = 0;
hr = pPicture->get_Width(&nWidth);
hr = pPicture->get_Height(&nHeight);
At this point, hr is S_OK, and nWidth and nHeight are each 0x1a7 or 423.
Since my original bitmap is 16x16, it seems like I've probably hit a snag
already.
But I go on to do:
CComPtr<IPictureDisp> pPictureDisp;
hr = pPicture->QueryInterface(&pPictureDisp);
if (FAILED(hr))
return hr;
hr = spCmdButton->put_Picture(pPictureDisp);
if (FAILED(hr))
return hr;
put_Picture is returning E_FAIL.
Any ideas why?
Thanks in advance,
Alun.
~~~~
CommandBarButton.
The usual technique I've seen listed is to open the clipboard, empty it,
fill it with the bitmap, then call PasteFace on the button.
Obviously, this is less than desirable, because it wipes out the content of
the clipboard.
I'm trying to use put_Picture, but can't get it to work. If you've had
success with this, please let me know, otherwise perhaps you could look at
the code below and tell me if I'm doing anything obviously wrong:
HBITMAP hBmp = LoadBitmap((HINSTANCE)gInstance,
MAKEINTRESOURCE(IDB_BITMAP1));
HRESULT hr;
CComPtr<IPicture> pPicture;
PICTDESC pd;
ZeroMemory(&pd,sizeof pd);
pd.cbSizeofstruct = sizeof pd;
pd.picType = PICTYPE_BITMAP;
pd.bmp.hbitmap = hBmp;
pd.bmp.hpal = 0;
hr = OleCreatePictureIndirect( &pd,
__uuidof(pPicture),
FALSE,
(LPVOID *)&pPicture );
if (FAILED(hr))
return hr;
OLE_XSIZE_HIMETRIC nWidth = 0;
OLE_YSIZE_HIMETRIC nHeight = 0;
hr = pPicture->get_Width(&nWidth);
hr = pPicture->get_Height(&nHeight);
At this point, hr is S_OK, and nWidth and nHeight are each 0x1a7 or 423.
Since my original bitmap is 16x16, it seems like I've probably hit a snag
already.
But I go on to do:
CComPtr<IPictureDisp> pPictureDisp;
hr = pPicture->QueryInterface(&pPictureDisp);
if (FAILED(hr))
return hr;
hr = spCmdButton->put_Picture(pPictureDisp);
if (FAILED(hr))
return hr;
put_Picture is returning E_FAIL.
Any ideas why?
Thanks in advance,
Alun.
~~~~