SetBKMode( ) 函数详解

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 */
    {
        HDC hdc = GetDC(hWnd);
        SetBkMode(hdc,TRANSPARENT);
        TextOut(hdc,20,20,"Hello World",11);
        DeleteDC(hdc);
        break;
    }
    
    /* 当设置背景模式为OPAQUE */
    case WM_PAINT:
    {
        HDC hdc = GetDC(hWnd);
        
        COLORREF cbrush = GetDCBrushColor(hdc);
        //该函数获取一个RGB颜色值中的红色强度值
        int iRed = GetRValue(cbrush);   
        int iGreen = GetGValue(cbrush);
        int iBlue = GetBValue(cbrush);
        
        SetBkMode(hdc,OPAQUE);
        TextOut(hdc,20,20,"Hello World",11);
        DeleteDC(hdc);
        break;
    }

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值