SetTextColor

2.x

  COLORREF SetTextColor(hdc, clrref)    
  HDC hdc; /* handle of device context */
  COLORREF clrref; /* new color for text */

The SetTextColor function sets the text color to the specified color. The system uses the text color when writing text to a device context and also when converting bitmaps between color and monochrome device contexts.

Parameters

hdc

Identifies the device context.

clrref

Specifies the color of the text.

Return Value

The return value is the RGB (red-green-blue) value for the previous text color, if the function is successful.

Comments

If the device cannot represent the specified color, the system sets the text color to the nearest physical color.

The background color for a character is specified by the SetBkColor and SetBkMode functions.

Example

The following example sets the text color to red if the GetTextColor function determines that the current text color is black. The text color is specified by using the RGB macro.

DWORD dwColor;

dwColor = GetTextColor(hdc);
if (dwColor == RGB(0, 0, 0))    /* if current color is black */
    SetTextColor(hdc, RGB(255, 0, 0)); /* sets color to red  */

See Also

GetTextColor, BitBlt, SetBkColor, SetBkMode