CMFCToolbar:无法动态显示工具栏按钮上的图标 [英] CMFCToolbar : Unable to display icon on Toolbar button dynamically

查看:648
本文介绍了CMFCToolbar:无法动态显示工具栏按钮上的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们要加载图标并想在工具栏中显示该图标按钮。但是我们无法在动态添加的工具栏按钮上显示图标。这与旧的CToolbar类工作正常。请查看给定的示例代码。我们在工具栏上设置了PNG图像。可能无法用HBITMAP更新现有的png图像。



// hIcon是新图标图像的处理程序



if (hIcon)


{


CMFCToolBarImages * pImgList;


pImgList = mytoolbar.GetImages();


int Index = mytoolbar.CommandToIndex(nID);


CMFCToolBarButton * pButtonInfo = mytoolbar.GetButton(nIndex);



// UpdateImg在使用图标更新现有图像时失败了:pImgList-> UpdateImage(pButtonInfo-> GetImage(),(HBITMAP)hIcon);
mytoolbar.SetUserImages(pImgList);


< p class = MsoNormal style ="margin:0in 0in 12pt 0.25in"> mytoolbar.Invalidate(TRUE) ;


< span style ="font-size:small"> :: DestroyIcon(hIcon);


}




解决方案

有谁有任何想法如何将自定义图像放在CMFCToolBar上? 我看到CMFCToolBarButton构造函数具有自定义图像的用户定义标志,但是没有示例如何操作。


Hi,

We want to load an icon and want to display that icon in a toolbar button. But we are unable display the icon on a dynamically added toolbar button. This was working fine with the old CToolbar class. Please have a look at the given sample code. We set PNG image on Toolbar. Might be it failed in updating existing png image with HBITMAP.


//hIcon is handler of new icon image

 if(hIcon)

{

      CMFCToolBarImages *pImgList;

     pImgList = mytoolbar.GetImages();

      int Index = mytoolbar.CommandToIndex(nID);

      CMFCToolBarButton *pButtonInfo = mytoolbar.GetButton(nIndex);


      //UpdateImg is failed in updating existing image with icon
      pImgList->UpdateImage(pButtonInfo->GetImage(),(HBITMAP)hIcon);

      mytoolbar.SetUserImages(pImgList);

      mytoolbar.Invalidate(TRUE);

      ::DestroyIcon( hIcon );

}

 

 

解决方案

Is anyone has any idea how to put custom image on CMFCToolBar?  I saw the CMFCToolBarButton constructor has user-defined flag for custom image, but there is no sample how to do it.


这篇关于CMFCToolbar:无法动态显示工具栏按钮上的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆