SetBkMode与SetBkColor理解
SetBkColor是背景颜色,SetBkMode是背景模式。
SetBkMode(hdc,TRANSPARENT);
This function sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and with non-solid pen styles.
这个函数设置指定设备上下文的背景混合模式,背景混合模式被用于文本,阴影画刷,和non-solid pen风格(勉强翻译,见笑了)
int SetBkMode( HDC hdc, int iBkMode );
Parameters
- hdc
- [in] Handle to the device context.
- iBkMode
- [in] Specifies the background mode.
It is either 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. 你看它没有设置颜色的功能,只有设置背景是否透明的这两个参数
对透明的理解:在窗体或控件输出的字符串或图形是有背景色的。而窗体或控件也是有背景色的。这两种背景色一般是不同的, 这样输出图形或字符串时,两种背景(窗体或控件的背景色、符串或图形的背景色)重叠在一起了,影响美观,为了不让这两种背景重叠,可以设置背景模式为TRANSPARENT(透明的),即让输出的字符串或图形的背景色不可见。可以这样理解:把输出的字符串或图形的背景色看成是一物体,窗体或控件看成另一物体,字符串或图形在窗体或控件前面挡住窗体或控件了(因为输出 的字符串或图形是画在窗体或控件上的,所以可以这么类比),但是透过字符串或图形能看到窗体或控件。即字符串或图形的背 景色所代表的物体是透明的。
SetBkColor(hdc,GetSysColor(COLOR_INACTIVECAPTION))
该函数用指定的颜色值来设置当前的背景色,如果指定的颜色值超出了当前设备的表示范围,则设置为最近似的、设备可以表示的颜色。
This function sets the current background color to the specified color. If the device cannot represent the specified color, it sets the background color to the nearest physical color.
COLORREF SetBkColor( HDC hdc, COLORREF crColor );
Parameters
- hdc
- [in] Handle to the device context.
- crColor
- [in] Specifies the new background color.
Return Values
If the function succeeds, the return value specifies the previous background color as a COLORREF value.
If the function fails, the return value is CLR_INVALID.
To get extended error information, call GetLastError.
Remarks
This function fills the gaps between styled lines drawn using a pen created by the CreatePen function.(gaps 差异)
The SetBKColor function also sets the background colors for the ExtTextOut function.
If the background mode is OPAQUE, the background color is used to fill gaps between styled lines, gaps between hatched lines in brushes, and character cells.
The background color is also used when converting bitmaps from color to monochrome and vice versa.
下图是有无SetMode模式的对比
SetMode模式
非SetMode模式