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.

ValueDescription
OPAQUEBackground is filled with the current background color before the text, hatched brush, or pen is drawn.
TRANSPARENTBackground 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模式

转载于:https://www.cnblogs.com/xzlq/archive/2013/06/04/3116641.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值