Click here to Skip to main content
Rate this: bad
good
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: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 23-Jun-13 21:24pm
moon_lu586
Comments
KarstenK at 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
good
Please Sign up or sign in to vote.

Solution 1

    CBitmap bmpPlayer;
	bmpPlayer.LoadBitmap(IDBMP_PLAYER1);
	m_pdcPlayerMem->CreateCompatibleDC(NULL);
	m_pdcPlayerMem->SelectObject(&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;
         m_bmCB1.LoadBitmap(IDBMP_CARDBACK_0);
	HBITMAP hcb1 = (HBITMAP)m_bmCB1.GetSafeHandle();
	m_bbCB1.SetBitmap(hcb1);
 
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
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