MFC GID 六大对象学习(CPen画笔类,CBrush画刷类,CFont字体类,CBitmap位图类,CRgn区域类)

1.CPen画笔类,对应结构体LOGPEN,

typedef struct tagLOGPEN {
  UINT      lopnStyle;
  POINT     lopnWidth;
  COLORREF  lopnColor;
} LOGPEN, *PLOGPEN, NEAR *NPLOGPEN, FAR *LPL

/*
lopnStyle:表示逻辑笔的样式,包括
 Pen Styles
//PS_SOLID            0
//PS_DASH             1       /* -------  */
//PS_DOT              2       /* .......  */
//PS_DASHDOT          3       /* _._._._  */
//PS_DASHDOTDOT       4       /* _.._.._  */。
//lopnWidth:表示笔的宽度(以像素为单位),可以是一个二元组 (x, y)。对于水平和垂直线条来说,
//通常将其设置为 (x, 0) 或 (0, y)。
//lopnColor:表示笔的颜色,使用 RGB 宏定义或 COLORREF 类型。
*/
class CPen : public CGdiObject
{
public:
    
   BOOL CreatePen(int nPenStyle, int nWidth, COLORREF crColor);//创建画笔对象。
   BOOL CreatePen(int nPenStyle, int nWidth, const LOGPEN* lpLogPen,
         int nStyleCount = 0, const DWORD* lpStyle = NULL);创建画笔对象。
   BOOL CreatePenIndirect(LPLOGPEN lpLogPen);创建画笔对象。
   BOOL DeleteObject();删除画笔对象。
   operator HPEN() const;//将 CPen 对象转换为 HPEN 类型
   int GetLogPen(LOGPEN* pLogPen) const;//检索与画笔相关的逻辑画笔信息
};

2.CBrush画刷类,

class CBrush : public CGdiObject
{
public:
   BOOL CreateSolidBrush(COLORREF crColor);//创建实心画刷对象。
   BOOL CreateHatchBrush(int nIndex, COLORREF crColor);//创建阴影画刷对象。
   /* Hatch Styles    nIndex 类型如下
   // #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 */
    */
   BOOL CreatePatternBrush(CBitmap* pBitmap);//创建图案画刷对象
   BOOL CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage);
   BOOL CreateDIBPatternBrush(const void* lpPackedDIB, UINT nUsage);
    //创建 DIB图案画刷对象。
   BOOL CreateSysColorBrush(int nIndex);//创建系统颜色画刷对象。
   BOOL CreateStockObject(int nIndex);//创建库存画刷对象。
   BOOL DeleteObject();//删除画刷对象。
   operator HBRUSH() const;//将 CBrush 对象转换为 HBRUSH 类型,
};

3.CFont字体类,

class CFont : public CGdiObject
{
public:
   BOOL CreateFontIndirect(const LOGFONT* lpLogFont);
   BOOL CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL);
   BOOL CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC = NULL);
   BOOL CreateStockObject(int nFont);
   BOOL DeleteObject();
   operator HFONT() const;
};
/*
CreateFontIndirect():根据 LOGFONT 结构体中指定的字体信息创建字体对象。
CreatePointFont():根据字号、字体名称和设备上下文创建字体对象。
CreatePointFontIndirect():根据 LOGFONT 结构体中指定的字体信息和设备上下文创建字体对象。
CreateStockObject():创建库存字体对象。
DeleteObject():删除字体对象。
operator HFONT():将 CFont 对象转换为 HFONT 类型。
*/

 .CFont 的相关结构体LOGFONT :使用方法

CFont myFont;
LOGFONT lf;
lf.lfHeight = 12; // 字体高度
lf.lfWeight = FW_BOLD; // 字体粗细
lf.lfItalic = TRUE; // 是否斜体
lstrcpy(lf.lfFaceName, _T("Arial")); // 字体名称

myFont.CreateFontIndirect(&lf);

4.CBitmap位图类,

5.CRgn区域类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值