Setting the picture of a command bar button for add-in

N

NickP

Hi there,

Im using the following code to obtain an IPicture reference from a 16x16
custom binary resource of a bitmap.

-----------

IPicture *LoadPicture(const unsigned char *data, size_t len)
{
HRESULT hr = NULL;
IPicture *pic = NULL;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, len);
LPVOID pvData = GlobalLock(hGlobal);
memcpy(pvData,data,len);
GlobalUnlock(hGlobal);
LPSTREAM pStream = NULL;
hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
if(SUCCEEDED(hr))
{
hr = OleLoadPicture(pStream, len, FALSE, IID_IPicture, (void
**)&pic);
pStream->Release();
if(SUCCEEDED(hr))
return(pic);
else
return(NULL);
}
else
return(NULL);
}

IPicture *GetButtonIcon()
{
HRSRC res = FindResource(g_hModule, MAKEINTRESOURCE(IDB_MYICON),
"BINARY");
if (res)
{
HGLOBAL mem = LoadResource(g_hModule, res);
void *data = LockResource(mem);
size_t sz = SizeofResource(g_hModule, res);
IPicture *pIPeIcon = LoadPicture((u_char*)data, sz);
return(pIPeIcon);
}
else
return(NULL);
}

-----------

From what I know the picture seems to be loading okay but I have no idea
how to set it to the command bar button...

vtParam.vt = VT_I4;
vtParam.lVal = 3;
hr = PutProperty(vtButton.pdispVal, L"Style", &vtParam);
if (FAILED(hr)) goto cleanup;

vtParam.vt = VT_I4;
vtParam.punkVal = GetButtonIcon();
hr = PutProperty(vtButton.pdispVal, L"Picture", &vtParam);
if (FAILED(hr)) goto cleanup;

I dont believe I am passing the information correctly to the object, how
would I do this correctly? Thanks loads in advance.

Nick.
 
N

NickP

For those of you who want to know how it's done, you need to,

1. Load bitmap into HBITMAP using LoadBitmap call
2. Open clipboard
3. Empty clipboard
4. Copy HBITMAP into clipboard
5. Close clipboard
6. Invoke PasteFace method of button

Nick.
 

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