Color Models Used by the Color Dialog Box

The custom colors extension of the Color dialog box allows the user to specify a color using RGB or HSL values. However, the CHOOSECOLOR structure uses only RGB values to report the colors created or selected by the user.

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 range from 0 through 255, with 0 indicating minimum intensity and 255 indicating maximum intensity. The following illustration shows how the primary colors red, green, and blue can be combined to produce four additional colors. (For display devices, the color black results when the red, green, and blue values are set to 0. In 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

The system stores internal colors as 32-bit RGB values that have the following hexadecimal form:

0x00bbggrr 
 

The low-order byte contains a value for the relative intensity of red; the second byte contains a value for green; and the third byte contains a value for blue. The high-order byte must be zero.

You can use the RGB macro to get an RGB value based on specified intensities for the red, green, and blue components. Use the GetRValue, GetBValue, and GetGValue macros to extract individual colors from an RGB color value.

HSL Color Model

The Color dialog box provides controls for specifying HSL values. The following illustration shows the color spectrum control and the luminosity slide control that appear in the Color dialog box. The illustration also 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.

Converting HSL Values to RGB Values

The dialog box procedure provided in COMDLG32.DLL for the Color dialog box contains code that converts HSL values to the corresponding RGB values. Following are several colors and 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)