简体   繁体   English

什么是MFC的算法或函数来计算控件的高光,阴影等?

[英]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. 我已经创建了一个CButtonColorButton子类,在样式中设置了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.

相关问题 从JPEG图像中提取亮度的正确方法是什么(伽玛等)? - What's the correct way to extract brightness out of a JPEG image (gamma corr., etc.)? 在单独的GUI类(菜单,工具栏等)之间共享操作的最佳方法是什么? - What's the best way to share actions between separate GUI classes (menu, toolbars, etc.) 什么是具有最简单学习曲线的C ++ GUI构建选项 - VS / Qt / wxWidgets /等? - What's the C++ GUI building option with the easiest learning curve - VS/Qt/wxWidgets/etc.? 将货币金额汇总到最接近的镍,季度,1美元,5美元等面额的最佳方法是什么? - What's the best way to round monetary amounts to the nearest nickel, quarter, $1, $5, etc. denominations? C ++中'和','或'等关键字的目的是什么? - What is the purpose of the 'and', 'or', etc. keywords in C++? “modf()”(来自 C/C++ 等的数学 function 等)的简写是什么? - what is “modf()” (a math function from C/C++ etc.) shorthand for? 安全[是/否]; [1/2/3 / etc。]功能 - Safe [Y/N]; [1/2/3/etc.] function 在MFC的InitInstance函数中创建的对象的生命周期有什么特别之处? - What is special about the lifetime of objects created in MFC's InitInstance function? 使用包含%1,%2等的格式字符串,而不是%d,%s等。 - Linux,C ++ - Use format strings that contain %1, %2 etc. instead of %d, %s etc. - Linux, C++ 替代 std::function 将函数作为参数传递(回调等) - Alternative to std::function for passing function as argument (callbacks, etc.)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM