本文介绍了如何使用XML在开发功能区中将.bmp加载到按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

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);
}





上述情况在2008年运作良好。不确定VS2012。



或者您可以尝试:





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);


这篇关于如何使用XML在开发功能区中将.bmp加载到按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 05:17