GDI使用方法小结(一)

来源:互联网 发布:java 异步写文件 编辑:程序博客网 时间:2024/06/04 22:34

一:DC相关

CDC* GetDC();

HDC* GetSafeHdc();

int ReleaseDC(CDC* pDC);

DC相关的类有:CDC, CClientDC, CPaintDC, CwindowDC, CMetaFileDC, 其中OnPaint()和OnDraw()函数只能使用CPaintDC类

二:画笔创建函数

1、构造函数:CPen(int nPenStyle, int nWidth, COLORREF crColor);

2、HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor);

3、HGDIOBJ GetStockObject(int fnObject);参数有BLACK_PEN,NULL_PEN,WHITE_PEN

4、HPEN CreatePenIndirect(const LOGPNE* logpen);

LOGPEN 的定义为:

typedef struct tagLOGPEN

{

   UINT lopnStyle;

   POINT lopnWidth;

   COLORREF lopnCOlor;

}LOGPEN 

三:画刷创建函数

1、构造函数:CBrush(int fnStyle, COLORREF crColor);

2、HBRUSH CreateHatchBrush(int fnStyle, COLORREF crColor);

3、HGDIOBJ GetStockObject(int fnObject);参数有BLACK_BRUSH,GRAY_BRUSH,DKGRAY_BRUSH,NULL_BRUSH等

4、HBRUSH CreateBrushIndirect(CONST LOGBRUSH* lplb);

四:字体创建函数

1、HFONT CreateFont(

int nHeight, int nWidth, int nEscapement,

int nOrientation, int fnWeight, DWORD fdwltalic,

DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fwdCharSet,

DWORD fdwOutputPrecision, DWORD fdwClipPrecision,

DWORD fdwQuality,DWORD fdwPitchAndFamily,LPCTSTR lpszFace);

2、HGDIOBJ GetStockObject(int fnObject);参数有ANSI_FIXED_FONT, ANSI_VAR_FONT, SYSTEM_FONT等

3、BOOL CreateFontIndirect(Const LOGFONT* lpLogFont);

五:点的创建

WIN API点结构:typedef struct tagPOINT{LONG x; LONG y;}POINT

MFC点类为:CPoint

1、构造函数:CPoint(int x,int y);

2、CPoint(POINT pt);

3、CPoint(SIZE sz)或CPoint(CSIZE sz)

4、CPoint(DWORD dw)其中双字节dw的高位表示横坐标,低位表示纵坐标

六:矩形的创建

WIN API矩形结构体为RECT, MFC矩形类为CRect。

1、CRect();构造一个空矩形

2、CRect(int l,int t, int r, int b);

3、CRect(const RECT& srcRect);

4、CRect(LPCRECT lpSrcRect);

5、CRect(POINT point, SIZE size);

6、CRect(POINT topLeft, POINT bottomRight);


0 0
原创粉丝点击