在具有正确透明度的 CMenu 中的菜单项旁边显示位图的简单方法 [英] Simple way to show a bitmap next to a menu item in a CMenu with correct transparency
问题描述
首先,我不是 C++ 开发人员,我主要使用 C# 进行编程.我正在尝试使用 .NET 中的 ContextMenu(是的,我知道 ContextMenuStrip)类,它是我的应用程序中 CMenu 的包装器.
First off, I'm not a C++ developer, I program mainly in C#. I am trying to use the ContextMenu (yes I'm aware of ContextMenuStrip) class in .NET which is a wrapper around CMenu in my application.
如何在具有适当透明度的菜单项旁边显示图像?
到目前为止我所做的是调用 SetMenuItemBitmaps 在我的菜单项上,这是附加的结果:
What I've done so far is call SetMenuItemBitmaps on my menu item, here is the attached result:
如您所见,菜单项上有一个白色背景.这与我想要的非常接近.我怎样才能让透明度问题消失?我在此菜单项上附上了我在下面使用的确切图片:
As you can see there is a white background on the menu item. This is just so frustratingly close to what I want. How can I get the transparency issues to go away? I've attached the exact image I used below on this menu item:
我知道 SetMenuItemBitmaps 不适用于彩色图像.
I know that SetMenuItemBitmaps is not meant for colored images.
选中的清晰位图应该是单色的.该系统采用布尔 AND 运算符将位图与菜单组合在一起,以便白色部分变为透明,黑色部分变为菜单项颜色.如果使用彩色位图,结果可能是不受欢迎.
那么正确的(希望是简单的)方法是什么?
So what is the proper (hopefully simple) way of doing this?
编辑
我尝试的另一件事是调用 SetMenuItemInfo,但我不断收到错误 87(无效参数).
Another thing I tried was calling SetMenuItemInfo, but I keep getting error 87 (invalid parameter).
这是在我调用 SetMenuItemInfo 之前 MENUITEMINFO 结构的样子:
This is what the MENUITEMINFO structure looks like before I call SetMenuItemInfo:
我在 SetMenuItemInfo 上调用的参数值是:
And the values for the parameters I call on SetMenuItemInfo are:
hMenu - ContextMenu 的句柄?
hMenu - The handle to the ContextMenu?
uItem - 0(第一个项目索引?)
uItem - 0 (the first item index?)
fByPosition - 真
lpmii - (上面的结构内容)
lpmii - (the structure contents above)
推荐答案
添加菜单项时,只需设置 MIIM_BITMAP
标志并在 HBITMAP
中传递 HBITMAP
code>hbmpItem MENUITEMINFO
结构的成员.如果您的位图是 32bpp 并带有预乘 alpha,那么它将正确显示.
When you add the menu item, simply set the MIIM_BITMAP
flag and pass the HBITMAP
in the hbmpItem
member of the MENUITEMINFO
structure. If your bitmap is 32bpp with pre-multiplied alpha then it will be displayed correctly.
这篇关于在具有正确透明度的 CMenu 中的菜单项旁边显示位图的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!