December 12th, 2007

When selecting system colors, match but don't mix

Here’s a question that came in from a customer:

Is there a way to view all the Windows color schemes at once? We want to display text in the COLOR_BTNTEXT color against a background of COLOR_INACTIVECAPTION, and we want to check that this looks good in all of the themes.

A mistake I see from some programs is mixing system colors that are not meant to be mixed. The colors I’m talking about are the ones obtained from the GetSysColor function. Here are the text and background color pairs, with a sample of what those colors are on a default install of Windows XP.

Text Background Sample
COLOR_WINDOWTEXT COLOR_WINDOW sample
COLOR_HOTLITE COLOR_WINDOW sample
COLOR_HIGHLIGHTTEXT COLOR_HIGHLIGHT sample
COLOR_INFOTEXT COLOR_INFOBK sample
COLOR_MENUTEXT COLOR_MENU sample
COLOR_BTNTEXT COLOR_BTNFACE sample
COLOR_CAPTIONTEXT COLOR_ACTIVECAPTION sample
COLOR_INACTIVECAPTIONTEXT COLOR_INACTIVECAPTION sample

If you’re going to combine colors, and you need them to contrast against each other (for example, because you’re going to draw text with them as the foreground and background colors), choose a pair from one of the rows above. Do not choose colors from different rows because there is no guarantee that they will be readable against each other. For example, I like to use black on #71FFFF as my color scheme for highlighted text. I’ve seen programs which break the above rule and draw text in the COLOR_HIGHLIGHT color against a background of COLOR_WINDOW, on the assumption that the highlight color contrasts against the window color. (They get away with this in the default Windows XP color scheme because the window color is white and the highlight color is medium blue.) Unfortunately, on my machine, this results in text that is extremely painful on the eyes. Remember: When it comes to system colors, match. Don’t mix.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.