GetBkColor

2.x

  COLORREF GetBkColor(hdc)    
  HDC hdc; /* handle of device context */

The GetBkColor function returns the current background color.

Parameters

hdc

Identifies the device context.

Return Value

The return value is an RGB (red, green, blue) color value if the function is successful.

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.

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

GetBkMode, SetBkColor, SetBkMode