Graphic Modes
Windows supports five graphic modes that allow an application to specify how colors are mixed, where output appears, how the output is scaled, and so on. These modes, which are stored in a DC, are described in the following table.
Graphics mode | Description |
Background | Defines how background colors are mixed with existing window or screen colors for bitmap and text operations. |
Drawing | Defines how foreground colors are mixed with existing window or screen colors for pen, brush, bitmap, and text operations. |
Mapping | Defines how graphics output is mapped from logical (or world) space onto the window, screen, or printer paper. |
Polygon-fill | Defines how the brush pattern is used to fill the interior of complex regions. |
Stretching | Defines how bitmap colors are mixed with existing window or screen colors when the bitmap is compressed (or scaled down). |
As it does with graphic objects, the system initializes a DC with default graphic modes. An application can retrieve and examine these default modes by calling the following functions.
Graphics mode | Function |
Background | GetBkMode |
Drawing | GetROP2 |
Mapping | GetMapMode |
Polygon-fill | GetPolyFillMode |
Stretching | GetStretchBltMode |
An application can change the default modes by calling one of the following functions.
Graphics mode | Function |
Background | SetBkMode |
Drawing | SetROP2 |
Mapping | SetMapMode |
Polygon-fill | SetPolyFillMode |
Stretching | SetStretchBltMode |
SetBkMode
The SetBkMode function sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.
int SetBkMode( HDC hdc, // handle to DC int iBkMode // background mode );
Parameters
-
hdc
- [in] Handle to the device context. iBkMode
- [in] Specifies the background mode. This parameter can be one of the following values.
Value | Description |
OPAQUE | Background is filled with the current background color before the text, hatched brush, or pen is drawn. |
TRANSPARENT | Background remains untouched. |
Return Value
If the function succeeds, the return value specifies the previous background mode.
If the function fails, the return value is zero.
Remarks
The SetBkMode function affects the line styles for lines drawn using a pen created by the CreatePen function. SetBkMode does not affect lines drawn using a pen created by the ExtCreatePen function.
The iBkMode parameter can also be set to driver-specific values. GDI passes such values to the device driver and otherwise ignores them.
Example
void CDeviceContextDlg::OnPaint() CPaintDC dc(this); // device context for painting HDC hdc = ::GetDC(this->m_hWnd);
plf->lfWeight = FW_NORMAL; } |
执行效果
如果注释掉语句:
SetBkMode(hdc, TRANSPARENT);
执行效果图:
再次添加语句:
COLORREF tempCor = GetBkColor(hdc);
g_Trace.printInt(GetRValue(tempCor));
g_Trace.printInt(GetRValue(tempCor));
g_Trace.printInt(GetRValue(tempCor));
R,G,B三色分别为255,255,255. 白色
To be continued…. waterathena 209-03-16 20:55