Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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:http://msdn.microsoft.com/en-us/library /aa338202.aspx#OfficeCustomizingRibbonUIforDevelopers_Callbacks
sample Getimage callback using ATL com

[
  object,
  uuid(22E2DF3A-AC81-48FA-A08D-ACFEC433B20D),
  dual,
  helpstring("ICallbackInterface Interface"),
  pointer_default(unique)
 ]
 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=\"http://schemas.microsoft.com/office/2006/01/customui\" onLoad=\"OnLoad\" loadImage=\"OnGetImage\">"
   L"<ribbon>"
   L"<tabs>"
   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)
{
 HBITMAP bmp = ::LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
 if(bmp == NULL)
  MessageBox(0,"Error on Loading bitmap ","IFlex.AddinClass - CAddinClass::OnGetImage()",MB_OK);

 // Result
 HRESULT hr;
 // 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
Comments
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

CBitmap bmpPlayer;
bmpPlayer.LoadBitmap(IDBMP_PLAYER1);
m_pdcPlayerMem->CreateCompatibleDC(NULL);
m_pdcPlayerMem->SelectObject(&bmpPlayer);



C#
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;
     m_bmCB1.LoadBitmap(IDBMP_CARDBACK_0);
HBITMAP hcb1 = (HBITMAP)m_bmCB1.GetSafeHandle();
m_bbCB1.SetBitmap(hcb1);
 
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