how to draw a disabled icon(如何绘制禁用的图标)
问题描述
我终于开始为我们的下拉菜单添加图标了:
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.
这篇关于如何绘制禁用的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何绘制禁用的图标
基础教程推荐
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
