SetBkColor

2.x

  COLORREF SetBkColor(hdc, clrref)    
  HDC hdc; /* handle of device context */
  COLORREF clrref; /* color specification, */  

The SetBkColor function sets the current background color to the specified color.

Parameters

hdc

Identifies the device context.

clrref

Specifies the new background color.

Return Value

The return value is the RGB value of the previous background color, if the function is successful. The return value is 0x80000000 if an error occurs.

Comments

If the background mode is OPAQUE, the system uses the background color to fill the gaps in styled lines, the gaps between hatched lines in brushes, and the background in character cells. The system also uses the background color when converting bitmaps between color and monochrome device contexts.

If the device cannot display the specified color, the system sets the background color to the nearest physical color.

For information about color-bitmap conversions, see the descriptions of the BitBlt and StretchBlt functions.

Example

The following example uses the GetBkColor function to determine whether the current background color is white. If it is, the SetBkColor function sets it to red.

DWORD dwBackColor;

dwBackColor = GetBkColor(hdc);
if (dwBackColor == RGB(255, 255, 255)) { /* if color is white */
    SetBkColor(hdc, RGB(255, 0, 0));     /* sets color to red */
    TextOut(hdc, 100, 200, "SetBkColor test.", 16);
}

See Also

BitBlt, GetBkColor, GetBkMode, SetBkMode, StretchBlt