在 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);
看来应该可以了.
这与 this 的问题相同.然而,这个问题涉及到 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.
我发布的问题的答案表明,对于功能包工具栏具有透明度的 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.
相关文章