CBrush,CFont,CPen

本文详细介绍了C++中绘图对象CBrush、CFont和CPen的创建方法,包括使用不同参数初始化这些对象的具体步骤。例如,通过CreateSysColorBrush创建系统默认颜色的画刷,使用CreatePointFont创建指定字体大小的字体对象等。

 

一.CBrush创建方法

1.CreateSysColorBrush

Creates a brush that is the default system color.

CBrush brush;
brush.CreateSysColorBrush(COLOR_BTNFACE);

2.CreateSolidBrush
Initializes a brush with the specified solid color.

CBrush brush;
brush.CreateSolidBrush(RGB(255,0,0));

3.CreatePatternBrush(ImageBrush)
Initializes a brush with a pattern specified by a bitmap.

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);

4.CreateHatchBrush(阴影图案)
Initializes a brush with the specified hatched pattern and color.

CBrush brush;
brush.CreateHatchBrush(HS_BDIAGONAL, RGB(255, 0, 0));

image

5.CreateBrushIndirect(传入一个结构体)

LOGBRUSH logBrush;
logBrush.lbStyle = BS_HATCHED;
logBrush.lbColor = RGB(0, 192, 192);
logBrush.lbHatch = HS_CROSS;

// Declare an uninitialized CBrush ...

CBrush brush;
// ... and initialize it with the LOGBRUSH.

brush.CreateBrushIndirect(&logBrush);

二.CFont创建方法

1.CreatePointFont

This function provides a simple way to create a font of a specified typeface and point size.

m_pCFont = new CFont();
m_pCFont->CreatePointFont(90,_T("Tahoma"));

2.CreateFontIndirect

Initializes a CFont object with the characteristics given in a LOGFONT structure.

m_pCFont = new CFont();
m_pCFont->CreatePointFont(90,_T("Tahoma"));

// Initialize font
LOGFONT    LogFont;
m_pCFont->GetLogFont(&LogFont);
LogFont.lfWeight = FW_HEAVY;
m_pCFont->DeleteObject();
m_pCFont->CreateFontIndirect(&LogFont);

三.CPen使用方法

1.CreatePen

CPen myPen1, myPen2;

// Create a solid red pen of width 2.

myPen1.CreatePen(PS_SOLID, 2, RGB(255,0,0));

// Create a geometric pen.

LOGBRUSH logBrush;
logBrush.lbStyle = BS_SOLID;
logBrush.lbColor = RGB(0,255,0);
myPen2.CreatePen(PS_DOT|PS_GEOMETRIC|PS_ENDCAP_ROUND, 2, &logBrush);  

2.CreatePenIndirect

LOGPEN logpen;
CPen   cMyPen;

// Get the LOGPEN of an existing pen.

penExisting.GetLogPen(&logpen);

// Change the color to red and the width to 2.

logpen.lopnWidth.x = 2;
logpen.lopnColor = RGB(255, 0, 0);

// Create my pen using the new settings.

cMyPen.CreatePenIndirect(&logpen);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值