如何绘制禁用的图标
我终于开始为我们的下拉菜单添加图标了:
I'm finally getting around to adding icons to our pull down menus:
在这张图片中,您可以看到除了突出显示的线之外的所有内容都没有问题.突出显示的线很好,除了图标是彩色的,而不是灰色的.
In this image, you can see that everything but the highlighted line is okay. The highlighted line is fine except for the icon, which is drawn in color, instead of grayed.
我的代码基于极简主义方法:
http://www.codeproject.com/Articles/16529/Simple-Menus-That-Display-Icons-Minimalistic-Appro?msg=4166441#xx4166441xx
I'm basing my code off of a minimalist approach:
http://www.codeproject.com/Articles/16529/Simple-Menus-That-Display-Icons-Minimalistic-Appro?msg=4166441#xx4166441xx
基本上,这只需要我绘制图标,我不必使用自定义代码来管理菜单项的所有方面.很漂亮.
Basically, this only requires that I draw the icon, and I don't have to manage all aspects of a menu item using custom code. Pretty nifty.
它适用于我们的目的,除非选择禁用(灰色)的菜单项.
但是,当菜单项变灰并被选中时,绘制的图标会显示为启用时的样子.错误的.:(
It works for our purposes except when selecting a disabled (grayed) menu item.
But when the menu item is grayed and selected, then the drawn icon appears as it would if it were enabled. Wrong. :(
然而,当背景被突出显示/选择时,完全相同的绘图代码可以工作.
Yet the exact same drawing code works when the background is highlighted/selected.
这让我相信有一些完全包含在 HDC 中的声明必须控制图标的显示方式 - 因为以下代码在所有条件下都可以工作,但被选中:
::DrawIconEx(lpdis->hDC, lpdis->rcItem.left+0, lpdis->rcItem.top, pIcon->GetHandle(), pIcon->GetSize().cx, pIcon->GetSize().cy, 0, NULL, DI_NORMAL);
有谁知道 HDC 中封装了什么状态来控制 DrawIconEx 的功能?如果我可以在未选择绘图时复制所选绘图期间的 HDC 状态,我应该能够生成灰色图标,而无需借助手动对内存中的图标进行灰度化的 30-50 行实现.
Does anyone know what state is encapsulated in the HDC that would control how DrawIconEx functions? If I can replicate the HDC state during selected drawing as found when not-selected-drawing, I should be able to generate the grayed icons without resorting the 30-50 line implementations that manually gray-scale the icon in memory.
推荐答案
你可以使用:
DrawState(...)
API 函数,带有 DSS_DISABLED 标志,但我不确定输出的质量.
API function, with DSS_DISABLED flag, but I am not sure about the quality of the output.
相关文章