[英]What is MFC's algorithm or function for calculating controls' highlight, shadow, etc.?
I've made a ColorButton
subclass of CButton
, setting BS_OWNERDRAW
flag in styles. 我已经创建了一个
CButton
的ColorButton
子类,在样式中设置了BS_OWNERDRAW
标志。
It works fine: I can set its text, background, etc. etc. 它工作正常:我可以设置其文本,背景等。
However I don't want to have to set the minor colors manually (highlight, shadow, etc.) I have a heuristic to choose white or black for text based on background. 但是我不想手动设置次要颜色(高亮,阴影等)我有一个启发式选择白色或黑色的文本基于背景。 I could do the same for the other minor colors but my formulas would differ from what Windows would do were the same color the background, and thus look odd.
我可以对其他次要颜色做同样的事情,但是我的公式与Windows所做的不同,背景颜色相同,因此看起来很奇怪。 So:
所以:
Question: Is there any way to find out what Windows would return for GetSysColor(COLOR_BTNSHADOW)
with a given background color? 问题:有没有办法找出Windows会为给定背景颜色的
GetSysColor(COLOR_BTNSHADOW)
返回什么?
To anticipate an answer I see CMFCButton
allows custom colors without making a whole subclass. 为了预测答案,我看到
CMFCButton
允许自定义颜色而不需要创建一个完整的子类。 What I've seen again allows the micromanagement of setting every color, but not the high-level ability I'm looking for. 我再次看到的东西允许设置每种颜色的微观管理,但不是我正在寻找的高级能力。 I'd may rather stick with my solution as it's already running, and works on XP and later.
我可能更愿意坚持我的解决方案,因为它已经在运行,并且可以在XP及更高版本上运行。 (This is a freeware utility so who knows what old OS users might have.) That said, If there's a
CMFCButton
solution that would also be of interest. (这是一个免费软件实用程序,所以谁知道旧操作系统用户可能会有什么。)这就是说,如果有一个
CMFCButton
解决方案也会引起关注。
GetSysColor is not sensitive to the background color. GetSysColor对背景颜色不敏感。 It simply has its set of color entries (based on the visual style) and will return those values.
它只是有一组颜色条目(基于视觉样式)并将返回这些值。 If you want values that make sense for some other background you will need to come up with reasonable values yourself.
如果你想要对某些其他背景有意义的价值观,你需要自己想出合理的价值观。
Not a complete answer at all, but as long as the color is a monochrome (with RG and B components equal): 根本不是一个完整的答案,但只要颜色是单色(RG和B组件相等):
the highlight color is 127 + channelvalue / 2 (integer math) 高亮颜色是127 + channelvalue / 2(整数数学)
the shadow color is channelvalue / 3 * 2 (again integer math) 阴影颜色是channelvalue / 3 * 2(再次整数数学)
Example: a background with R, G, and B values of 200 would have a highlight of 227 and a shadow of 132. 示例:R,G和B值为200的背景的高光为227,阴影为132。
For non-gray backgrounds, a quite different calculation seems to take place. 对于非灰色背景,似乎发生了完全不同的计算。 I'm getting very usable results simply using the above formulas channel by channel, but the original question isn't "what would give usable results" but specifically "what is Windows' calculation?"
我只是逐个频道地使用上面的公式得到非常有用的结果,但原始问题不是“什么会给出有用的结果”,而是具体的“什么是Windows计算?”
Windows also has a dark shadow color which is invariably 0x404040 in every color I've tried. Windows也有一个深色阴影颜色,我试过的每种颜色总是0x404040。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.