CBrush::CreatePatternBrush

初始化使用位图指定模式的画笔。

BOOL CreatePatternBrush(
   CBitmap* pBitmap 
);

参数

  • pBitmap
    标识位图。

返回值

非零,如果成功;否则为0。

备注

画笔可以支持光栅操作的所有设备上下文随后被选择。 使用 CBitmap::CreateBitmapCBitmap::CreateBitmapIndirectCBitmap::LoadBitmapCBitmap::CreateCompatibleBitmap 功能,pBitmap 确定的位图通常初始化。

作为填充架构的位图应为8 x 8像素。 如果位图更大,Windows仅使用位与像素相对应的前8行和列在位图的左上角。

模式画笔可以删除,而不影响关联的位图。 这意味着位图可用于创建任意数量的模式画笔。

使用的单色位图创建的画笔(1色产生,每像素1位)使用当前文本和背景色,绘制。 位表示的像素设置为0绘制与当前文本颜色。 位表示的像素设置为1绘制与当前背景色。

有关使用 CreatePatternBrush的信息,Windows功能,请参见 Windows SDK。

示例

// Create a hatched bit pattern.
WORD HatchBits[8] = { 0x11, 0x22, 0x44, 0x88, 0x11,
   0x22, 0x44, 0x88 };

// Use the bit pattern to create a bitmap.
CBitmap bm;
bm.CreateBitmap(8,8,1,1, HatchBits);

// Create a pattern brush from the bitmap.
CBrush brush;
brush.CreatePatternBrush(&bm);

// Select the brush into a device context, and draw.
CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brush);
pDC->RoundRect(CRect(50, 50, 200, 200), CPoint(10,10));

// Restore the original brush.
pDC->SelectObject(pOldBrush);

要求

Header: afxwin.h

请参见

参考

CBrush选件类

层次结构图

CBitmap选件类

CBrush::CreateBrushIndirect

CBrush::CreateDIBPatternBrush

CBrush::CreateHatchBrush

CBrush::CreateSolidBrush

CGdiObject::CreateStockObject