Windows API——SetBkMode()函数学习

1.函数功能

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.

SetBkMode函数设置指定设备上下文的背景混合模式。 背景混合模式用于(文本)、(阴影画笔)和(非实线的笔样式)。

2.函数原型

int SetBkMode( HDC hdc, int mode );

参数:

hdc:当前DC的句柄。

mode:要设置的背景混合模式的模式。

/* Background Modes */
#define TRANSPARENT         1    //设置背景模式为透明的,即让输出的字符串或图形的背景色不可见
#define OPAQUE                    2    //用当前背景的画刷的颜色输出显示文字的背景,也就是不透明
#define BKMODE_LAST         2    //上一模式,也就是说背景模式只有两种,要么TRANSPARENT,要么OPAQUE

返回值:

If the function succeeds, the return value specifies the previous background mode.(返回之前的背景模式)

If the function fails, the return value is zero.(返回0)

3.备注

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.

4.测试结果

  • 当设置背景模式为TRANSPARENT

  • 当设置背景模式为OPAQUE

注:荧光笔标注的地方是获取当前背景画刷的颜色值,得到结果为RGB(255,255,255),即白色,所以"Hello World"的背景颜色为白色。

猜你喜欢

转载自blog.csdn.net/Small_SaltedFish/article/details/81094936