Click here to Skip to main content
11,922,381 members (31,596 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ VSTO
Sorry to bother you ,I want to use VC++ to create Excel Addin, in the XML document ,button control need image = bitmap.bmp ,the button need to load the bitmap.bmp, I see the report in: /aa338202.aspx#OfficeCustomizingRibbonUIforDevelopers_Callbacks
sample Getimage callback using ATL com
  helpstring("ICallbackInterface Interface"),
 interface ICallbackInterface : IDispatch
  [id(1), helpstring("method ButtonClicked")] HRESULT ButtonClicked([in] IDispatch* RibbonControl);
  [id(2), helpstring("method OnGetImage")] HRESULT OnGetImage([in] BSTR strValue, [out,retval] IPictureDisp** ppdispImage);
// IRibbonExtensibility
 STDMETHOD(GetCustomUI)(BSTR RibbonID, BSTR * RibbonXml)
        MessageBox(0,"Loading VC 6.0 COM xml schema here","IFlex.AddinClass - CAddinClass::GetCustomUI ",MB_OK);
  if (!RibbonXml)
   return E_POINTER;
  *RibbonXml = SysAllocString(
   L"<customUI xmlns=\"\" onLoad=\"OnLoad\" loadImage=\"OnGetImage\">"
   L"<tab idMso=\"TabData\">"
   L"<group id=\"customGroup\" label=\"IGXL(VS 6.0)\">"
    L"<button id=\"MsoImageBtn\" label=\"InBuiltImage\" size=\"large\" imageMso=\"FormatPainter\" onAction=\"ButtonClicked\" />"
    L"<button id=\"CustomImageBtn\" label=\"VS 6.0(COM)\" size=\"large\" image=\"bitmap.bmp\"  onAction=\"ButtonClicked\"  />"
   L" </group>"
   L" </tab>"
   L" </tabs>"
   L" </ribbon>"
   L"</customUI>" );
  return (*RibbonXml ? S_OK : E_OUTOFMEMORY);
//Associated callback for OnGetImage
STDMETHODIMP CAddinClass::OnGetImage(BSTR strValue, IPictureDisp ** ppdispImage)
 if(bmp == NULL)
  MessageBox(0,"Error on Loading bitmap ","IFlex.AddinClass - CAddinClass::OnGetImage()",MB_OK);
 // Result
 // Create the IPicture from the bitmap handle
 PICTDESC pictureDesc;
 ::ZeroMemory( &pictureDesc, sizeof(pictureDesc) );
 pictureDesc.cbSizeofstruct = sizeof(pictureDesc);
 pictureDesc.picType = PICTYPE_BITMAP;
 pictureDesc.bmp.hbitmap = static_cast<HBITMAP>( bmp );
 hr = ::OleCreatePictureIndirect( &pictureDesc, IID_IPicture, FALSE, reinterpret_cast<void **>(ppdispImage) );
 if ( FAILED(hr) )
  MessageBox( 0,_T("Error in creating picture from bitmap."),_T("IFlex.AddinClass - CAddinClass::OnGetImage()"),MB_OK );
  return S_OK;
 return S_OK;

I don't know why The OnGetImage can't be load,can you give me some help,thank you all.
Posted 23-Jun-13 21:24pm
KarstenK 24-Jun-13 3:02am
I cant answer your question but you better explain what works and what not. Where is the FIRST ERROR?

Tip: change the color depth of the pic to try different versions.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

CBitmap bmpPlayer;

void CView::OnDraw(CDC* pDC)
    pDC->BitBlt(600, 300, 150, 200, m_pdcPlayerMem,
        0, 0, SRCCOPY);

The above used to work well, in 2008. Not sure about VS2012.

Or you might try:

     CBitmap m_bmCB1; CBitmapButton m_bbCB1;
HBITMAP hcb1 = (HBITMAP)m_bmCB1.GetSafeHandle();

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

  Print Answers RSS
0 OriginalGriff 453
1 Dave Kreskowiak 335
2 Sergey Alexandrovich Kryukov 263
3 Richard MacCutchan 225
4 ppolymorphe 175
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100