Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Now ,I build an Excel 2007 Addin-in which has some controls.Now I want add bmp resource to the controls.
Office 2007 Addin add controls using XML,such as following. The menu control add bmp using image="camera.bmp" .According the MSDN
http://msdn.microsoft.com/en-us/library/office/bb462634%28v=office.12%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-4[^]
,the method just for C# and VBA,So if there any method can achieve adding bmp resource to the controls using C++,That's all thank you.
<customui xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadimage="LoadImage">
<ribbon startfromscratch="false">
<tabs>
<tab id="tab1" label="Menu Demo" keytip="x">
<group id="group1" label="Demo Group">
<menu id="menu1">
label="Text Handler"
itemSize="large"
getScreentip="GetScreenTip"
supertip="This is a super tip for the menu."
image="camera.bmp" >
<button id="button1"
imageMso="HappyFace"
getDescription="GetDescription"
label="My Button"
önAction="OnAction" />





"
Posted

1 solution

STDMETHOD(OnGetImage)(BSTR * pbstrImageId, IPictureDisp * * ppdispImage)
{
// MessageBox(NULL,"OnGetImage","AA",MB_OK);
CComBSTR bImageName(*pbstrImageId);
HRESULT hr = S_OK;
PICTDESC pd;
pd.cbSizeofstruct = sizeof (PICTDESC);
pd.picType = PICTYPE_BITMAP;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
gdiplusStartupInput.DebugEventCallback = NULL;
gdiplusStartupInput.SuppressBackgroundThread = FALSE;
gdiplusStartupInput.SuppressExternalCodecs = FALSE;
gdiplusStartupInput.GdiplusVersion = 1;
GdiplusStartup (&gdiplusToken, &gdiplusStartupInput, NULL);
int idPNG;

//if (lstrcmp (bstrID, TEXT("iJoinBtn")) == 0)
if(wcscmp(bImageName.m_str,L"crhs1.bmp")==0)
idPNG = IDR_PNG1;

if(wcscmp(bImageName.m_str,L"crhs2.bmp")==0)
idPNG = IDR_PNGBJHS;

if(wcscmp(bImageName.m_str,L"dwsj.bmp")==0)
idPNG = IDR_PNGDWSJ;

if(wcscmp(bImageName.m_str,L"sjj.bmp")==0)
idPNG = IDR_PNGSJJ;

if(wcscmp(bImageName.m_str,L"crdm.bmp")==0)
idPNG = IDR_PNGCRDM;

if(wcscmp(bImageName.m_str,L"crrq.bmp")==0)
idPNG = IDR_PNGCRRQ;
if(wcscmp(bImageName.m_str,L"cssz.bmp")==0)
idPNG = IDR_PNGCSSZ;
if(wcscmp(bImageName.m_str,L"xtsz.bmp")==0)
idPNG = IDR_PNGXTSZ;

if(wcscmp(bImageName.m_str,L"shuaxin.bmp")==0)
idPNG = IDR_SHUAXIN;
//if(wcscmp(bImageName.m_str,L"wdl.bmp")==0)
// idPNG = IDR_PNGWDL;
HRSRC hResource = FindResource (_Module.GetModuleInstance(),
MAKEINTRESOURCE(idPNG), TEXT("PNG"));
if (!hResource)
return hr;
DWORD dwImageSize = SizeofResource (_Module.GetModuleInstance(), hResource);
const void* pResourceData = LockResource (LoadResource
(_Module.GetModuleInstance(), hResource));
if (!pResourceData)
return hr;
HGLOBAL hBuffer = GlobalAlloc (GMEM_MOVEABLE, dwImageSize);
if (hBuffer)
{
void* pBuffer = GlobalLock (hBuffer);
if (pBuffer)
{
CopyMemory (pBuffer, pResourceData, dwImageSize);
IStream* pStream = NULL;
if (::CreateStreamOnHGlobal (hBuffer, FALSE, &pStream) == S_OK)
{
Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromStream (pStream);
pStream->Release();
if (pBitmap)
{
pBitmap->GetHBITMAP (0, &pd.bmp.hbitmap);
hr = OleCreatePictureIndirect (&pd, IID_IDispatch, FALSE, (LPVOID*)ppdispImage);
delete pBitmap;

}
}
GlobalUnlock (pBuffer);
}
GlobalFree (hBuffer);
}
Gdiplus::GdiplusShutdown(gdiplusToken);
return hr;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900