0

I've made a ColorButton subclass of CButton, setting BS_OWNERDRAW flag in styles.

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. So:

Question: Is there any way to find out what Windows would return for GetSysColor(COLOR_BTNSHADOW) with a given background color?

To anticipate an answer I see CMFCButton allows custom colors without making a whole subclass. 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. (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.

Swiss Frank
  • 1,985
  • 15
  • 33

2 Answers2

0

GetSysColor is not sensitive to the background color. 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.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • "GetSysColor is not sensitive to the background color?" I think it's sensitive to the background color the user's set by default, isn't it? It's not just hardcoded to specific colors, I don't think. – Swiss Frank May 19 '19 at 06:16
  • The values GetSysColors returns come from the visual style (which can be set by the user) and can also be overriden by the user on a profile-wide basis. It is not sensitive to the background in the sense that if you set some non-standard background (with a background brush as part of window registration for example) GetSysColor will not somehow calculate values different from those it would return for a standard background. – SoronelHaetir May 20 '19 at 22:18
  • Of course, SoronelHaetir, which is why I'm asking what it's calculation is, so I can duplicate it. for other, what you call "non-standard" backgrounds. – Swiss Frank May 22 '19 at 05:19
0

Not a complete answer at all, but as long as the color is a monochrome (with R G and B components equal):

  • the highlight color is 127 + channelvalue / 2 (integer math)

  • the shadow color is channelvalue / 3 * 2 (again integer math)

Example: a background with R, G, and B values of 200 would have a highlight of 227 and a shadow of 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 also has a dark shadow color which is invariably 0x404040 in every color I've tried.

Swiss Frank
  • 1,985
  • 15
  • 33