创建阴影线画刷

=============================================================

标题:创建阴影线画刷

摘要:

备注:Windows CE

日期:2010.5.1

姓名:朱铭雷

=============================================================

    填充棒图,图表的时候,使用阴影线画刷能够使之更加醒目。其他版本的Windows系统可以通过CreateHatchBrush函数来创建,但Windows CE下不支持这个函数,只能通过其他方法来实现。

    下面这个函数,摘自《Programming Windows Embedded CE 6.0 Developer Reference,可以完成这个功能。

 

#define HS_HORIZONTAL       0       /* ----- */

#define HS_VERTICAL         1       /* ||||| */

#define HS_FDIAGONAL        2       /* / */

#define HS_BDIAGONAL        3       /* / */

#define HS_CROSS            4       /* +++++ */

#define HS_DIAGCROSS        5       /* xxxxx */

 

//----------------------------------------------------------------

// MyCreateHatchBrush - Creates hatched brushes

//

HBRUSH MyCreateHatchBrush (INT fnStyle, COLORREF clrref) {

    BRUSHBMP brbmp;

    BYTE *pBytes;

    int i;

    DWORD dwBits[6][2] = {

        {0x000000ff,0x00000000}, {0x10101010,0x10101010},

        {0x01020408,0x10204080}, {0x80402010,0x08040201},

        {0x101010ff,0x10101010}, {0x81422418,0x18244281},

    };

 

    if ((fnStyle < 0) || (fnStyle > dim(dwBits)))

        return 0;

    memset (&brbmp, 0, sizeof (brbmp));

 

    brbmp.bmi.biSize = sizeof (BITMAPINFOHEADER);

    brbmp.bmi.biWidth = 8;

    brbmp.bmi.biHeight = 8;

    brbmp.bmi.biPlanes = 1;

    brbmp.bmi.biBitCount = 1;

    brbmp.bmi.biClrUsed = 2;

    brbmp.bmi.biClrImportant = 2;

 

    // Initialize the palette of the bitmap.

    brbmp.dwPal[0] = PALETTERGB(0xff,0xff,0xff);

    brbmp.dwPal[1] = PALETTERGB((BYTE)((clrref >> 16) & 0xff),

                                (BYTE)((clrref >> 8) & 0xff),

                                (BYTE)(clrref & 0xff));

 

    // Write the hatch data to the bitmap. 

    pBytes = (BYTE *)&dwBits[fnStyle];

    for (i = 0; i < 8; i++)

        brbmp.bBits[i*4] = *pBytes++;

 

    // Return the handle of the brush created.

    return CreateDIBPatternBrushPt (&brbmp, DIB_RGB_COLORS);

}

    使用的时候,直接调用这个函数来创建阴影线画刷就可以了。如下:

HBRUSH hBr, hOldBr;

hBr = (HBRUSH) MyCreateHatchBrush (HS_DIAGCROSS, RGB (0, 0, 0));

hOldBr = (HBRUSH) SelectObject (hdc, hBr);

Rectangle (hdc, 100, 100, 140, 200);

SelectObject (hdc, hOldBr);

DeleteObject (hBr);

    效果如下:

     

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值