How does the desktop choose the icon label color?

Many system colors come in pairs, one for background and one for foreground. For example, COLOR_MENU and COLOR_MENUTEXT; COLOR_WINDOW and COLOR_WINDOWTEXT; COLOR_HIGHLIGHT and COLOR_HIGHLIGHTTEXT. More on these colors in a future blog entry.


How does the desktop choose the icon label color?

It's not very exciting.

The COLOR_DESKTOP color is studied to see if it is mostly dark or mostly light. If mostly dark, then the icon text is white. If mostly light, then the icon text is black.

This works great if you don't have a wallpaper. If you do, then the desktop color doesn't typically correspond to the dominant color in your wallpaper, which may lead to a poor choice of black vs. white.

To remedy this, you can manually set the desktop color by going to the Display control panel and going to the Desktop tab. Change the desktop color to something dark to get white icon text and to something light to get black icon text.

Comments (16)
  1. 4nd3r$ says:

    i actually made a program that sets the text color to anything u want and the background color to transparent

  2. What is the algorithm for deciding whether a color is light or dark?

  3. Raymond Chen says:

    I forget exactly; it’s probably just a standard luminance computation.

  4. Catatonic says:

    Maybe it’s just me… but my WinXP Pro desktop has a background image, and the icon text is always white with a dark drop shadow. Only if I turn off the image does the background colour affect the icon text.

  5. J. Edward Sanchez says:

    Yes; as you’ve observed, Windows XP works differently from older versions of Windows when you have the new "Use drop shadows for icon labels on the desktop" option enabled.

    This new feature provides the much-requested label-background transparency that some of us went to the trouble of hacking in ourselves in previous versions of Windows. In addition, the drop shadows make it easier to read icon labels against busy background images.

    If you’d like to play around with this option, it can be found by going into the Performance section of the Advanced tab of System Properties. It’s one of the Visual Effects that can be selectively disabled.

    When you remove your background image, Windows ignores the "drop shadows" option (if you have it enabled), and just reverts to the old behavior. This makes sense, since transparency and drop shadows aren’t needed if the icon label background already matches the desktop color.

  6. Juan Miguel Venturello says:

    Always was curious as to why MS put those ugly color boxes around the icon labels when there was a background image. Performance reasons? It was quite simple to write a program to do it from the source code I once read. As usual I know this decision was taken for reasons I cannot appreciate – as many things Raymond so nicely explains in this blog – any comment Raymond?

    Ps. THANKS for this blog!!

  7. Raymond Chen says:

    Without a box, text against a busy background becomes unreadable.

  8. Kevin Westhead says:

    Speaking of text colours, why does the Send To menu uses COLOR_MENUTEXT for its menu items on XP under the default XP style, even when the items are selected? If I switch to the Classic style, COLOR_HIGHLIGHTTEXT is used.

    Also, Explorer uses shading to emphasise the selected column in Details view. This appears to be a feature of the list-view control on XP (LVM_SETSELECTEDCOLUMN), but can you expand on how this colour is calculated? I’d imagine that it uses COLOR_WINDOW as a starting point but, as with the desktop font colour, there must be some rules based on how light or dark the current window background colour is.

  9. Raymond Chen says:

    Send To menu coloring: That’s just a bug.

    I don’t know how the sort shading color is calculated.

  10. J. Edward Sanchez says:

    Yes, it’s just a very simple — but not quite standard — luminance computation.

    I once wrote a program that allowed the user to specify any color for the desktop icon text and background (including transparent, of course).

    I wanted to provide a way for the user to specify "Automatic (Windows default)" for the desktop icon text, so I had to figure out precisely how Windows decided whether to make the text black or white.

    After some trial and error, I was able to come up with a simple algorithm that matched Windows’ under all circumstances:

    if ((2 * GetRValue(dwColorBack) + 5 * GetGValue(dwColorBack) + GetBValue(dwColorBack)) > 0x400)

    dwColorText = 0x00000000;


    dwColorText = 0x00FFFFFF;

    (I don’t know how to format code properly in these blog comments. If the above comes up garbled or hard to read, please feel free to fix it, Raymond. BTW, what tags are supported here?)

    The luminance formula that Windows uses strikes me as a little sloppy compared to most of the ones you’ll find. I suspect that this is due to a bit of optimization, which allows the computation to be done entirely in integer math. Since the luminance is needed only for a rough estimate of "light" or "dark" anyway, this doesn’t really matter.

  11. Centaur says:

    Speaking of wrong color luminance formulae…

    Remember how, when you click Start | Shut Down, the desktop slowly fades out to gray? Well, if you put up an image of a #0000FF bright blue square and a #FF0000 bright red circle, the square comes out brighter than the circle. The coefficients seem to be right, but their order is mixed up.

  12. mschaef says:

    Mr. Sanchez’s luminance forumula actually reminds me of the one Microsoft used to document back in QuickBasic 4.0 (IIRC, but I must admit I don’t remember what it was used for). Is this assigning different weights to different color channels typical of luminence calculations in general, or is this just a Microsoft thing?

  13. Petr Kadlec says:

    It’s a fact, nothing MS-specific. The coefficients are based on physical properties of a human eye. The most commonly used coefficients are 0.299, 0.587, 0.114 (IIRC it’s from NTSC standard).

  14. Ivo says:

    On a similar note, how do MS applications (Visual Studio for example) detect dark color schemes (High Contrast Black for example) so they can use different toolbar icons? Also, are the high contrast toolbar icons created automatically from the regular icons, or manually?

  15. DrPizza says:

    "On a similar note, how do MS applications (Visual Studio for example) detect dark color schemes (High Contrast Black for example) so they can use different toolbar icons?"

    How do they do it?

    Unreliably or not at all, in my experience.

    If they have an algorithm to do such a thing, I’ve not seen it, and I’ve seen plenty of dark colour schemes.

  16. Raymond Chen says:

    Commenting on this article has been closed.

Comments are closed.

Skip to main content