在MFC CMenu中绘制图标而不是位图? [英] Drawing icons instead of bitmaps in a MFC CMenu?

查看:278
本文介绍了在MFC CMenu中绘制图标而不是位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在菜单中使用位图

I can use an bitmap in a menu

CMenu men;
CBitmap b;
b.LoadBitmap(IDB_0); 
men.AppendMenu( MF_ENABLED,1,&b);

我可以将图标绘制到DC中

I can draw an icon into a DC

  CImageList IL;
  IL.Create(70, 14, ILC_COLOR16 | ILC_MASK, 1, 0);
  IL.Add(AfxGetApp()->LoadIcon(IDI_0));
  IL.Draw ( pDC,  0,  rcIcon.TopLeft(),  ILD_BLEND50 );

但是我找不到在菜单中显示图标的简单方法.我想这样做

But I cannot find a simple way to show an icon in a menu. I would like to do this

CMenu men;
CBitmap b;
// here the miracle happens, load the icon into the bitmap
men.AppendMenu( MF_ENABLED,1,&b);

似乎应该是可能的.

这是与相同的问题.但是,该问题涉及到MFC功能包,没有得到回答,而且一个月没有显示任何活动,因此我认为值得再次询问有关基本MFC的问题.

This is the same question as this. However that question referred to the MFC feature pack, did not get answered, and has shown no activity for a month, so I thought it would be worthwhile to ask it again in reference to basic MFC.

推荐答案

我问了您引用的问题.

向菜单添加(普通的16位彩色)图标的方法是使一个工具栏具有与要包含其图标的菜单相同的资源ID.然后,将ID分配给每个工具栏按钮,与菜单项相同的ID.制作一个向导生成的新MFC应用程序,您将在那里看到它的工作方式.

The way to add (normal, 16-bit color) icons to menus is to make a toolbar with the same resource id as the menu you want to have icons in. You then assign id's to each of the toolbar buttons, the same id's as the menu entries. Make a wizard-generated new MFC application and you'll see how it works there.

我发布的问题的答案表明,对于Feature Pack工具栏具有透明性的32位图像,该功能应该相同;我还没来得及测试.

The answers to the question I posted suggested that it should work the same for 32-bit images with transparency for the Feature Pack toolbars; I haven't gotten around to test it out though.

如果您的特定问题是如何制作动态生成的菜单,我认为您应该在工具栏中传递现有条目的ID,然后将使用该图像.

If your specific problem is how to make dynamically-generated menus, I think you should pass the id of an existing entry in a toolbar and then that image will be used.

这不是您问题的真正答案,但也许会为您指明正确的方向.

Not a real answer to your question but maybe it'll point you in the right direction.

这篇关于在MFC CMenu中绘制图标而不是位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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