4.1.1 Color Models Used by the Color Dialog Box

The Color dialog box uses two models for specifying colors: the RGB model and the HSL model. Regardless of the model used, internal storage is accomplished by use of the RGB model.

4.1.1.1 RGB Color Model

The RGB model is used to designate colors for displays and other devices that emit light. Valid red, green, and blue values are in the range 0 through 255, with 0 indicating the minimum intensity and 255 indicating the maximum intensity. The following illustration shows how the primary colors red, green, and blue can be combined to produce four additional colors. (With display devices, the color black results when the red, green, and blue values are set to 0—that is, with display technology, black is the absence of all colors.)

Following are eight colors and their associated RGB values:

Color RGB values

Red 255, 0, 0
Green 0, 255, 0
Blue 0, 0, 255
Cyan 0, 255, 255
Magenta 255, 0, 255
Yellow 255, 255, 0
White 255, 255, 255
Black 0, 0, 0

Windows stores internal colors as 32-bit RGB values. The high-order byte of the high-order word is reserved; the low-order byte of the high-order word specifies the intensity of the blue component; the high-order byte of the low-order word specifies the intensity of the green component; and the low-order byte of the low-order word specifies the intensity of the red component.

4.1.1.2 HSL Color Model

The Color dialog box provides controls for specifying HSL values. The following illustration shows the color spectrum control and the vertical luminosity control that appear in the Color dialog box and shows the ranges of values the user can specify with these controls.

In the Color dialog box, the saturation and luminosity values must be in the range 0 through 240 and the hue value must be in the range 0 through 239.

4.1.1.3 Converting HSL Values to RGB Values

The dialog box procedure provided in COMMDLG.DLL for the Color dialog box contains code that converts HSL values to the corresponding RGB values. Following are several colors with their associated HSL and RGB values:

Color HSL values RGB values

Red (0, 240, 120) (255, 0, 0)
Yellow (40, 240, 120) (255, 255, 0)
Green (80, 240, 120) (0, 255, 0)
Cyan (120, 240, 120) (0, 255, 255)
Blue (160, 240, 120) (0, 0, 255)
Magenta (200, 240, 120) (255, 0, 255)
White (0, 0, 240) (255, 255, 255)
Black (0, 0, 0) (0, 0, 0)