GDI(图形设备接口)

来源:百度文库 编辑:神马文学网 时间:2024/04/19 00:03:17
GDI操作函数
绘制文本TextOut和DrawText:
BOOL TextOut(HDC HDC,int nXStart,int nYStart,LPCTSTR lpString,int cbString)
int DrawText(HDC hdc,LPCTSTR lpString,int nCount,LPRECT lpRect,UINT uFormat)
TextOut根据坐标和长度绘制文本,DrawText则是给定一个矩形区域绘制文本。
绘制点SetPixel:
COLORREF SexPixel(HDC hdc,int x,int y,COLORREF crColor);
绘制直线MoveToEx和LineTo
BOOL MoveToEx(HDC hdc,int x,int y,LPPOINT lpPoint)
BOOL LineTo(HDC hdc,int nXEnd,int nYEnd)
绘制椭圆Ellipse
BOOL Ellipse(HDC hdc,int nLeftRect,int nTopRect,int RightRect,int nBottomRect)
绘制矩形FillRect与Rectangle
int FillRect(HDC hdc,CONST RECT *lprc,HBRUSH hbr)
BOOL Rectangle(HDC hdc,int nLeftRect,int nTopRect,int nRightRect,int nBottomRect)
MFC对GDI进行了封装,CDC是最基本的DC类,CClientDC与CWindowDC从CDC派生出来的。
例子:画椭圆
CClientDC *pClientDC = (CClientDC*)this->GetDC();
pClientDC->Ellipse(CRect(0,0,200,300));
字体:
CFont font,*pOldFont;
CClientDC *pClientDC = (CClientDC*)this->GetDC();
font.CreatePointFont(90,"宋体");  //创建字体
pOldFont=pClientDC->SelectObject(&font);//设置字体
pClientDC->TextOut(300,300,"ABC");//输出文本
pClientDC->SelectObject(pOldFont);//将先前字体设置回DC
画笔
BOOL CreatePen(int nPenStyle,int nWidth,COLORREF crColor)
画刷
CBrush()
CBrush(COLORREF crColor)
CBrush(CBitmap *pBitmap)
位图:使用CBitmap类来管理位图
载入:CBitmap::LoadBitmap从资源中载入,CBitmap::LoadImage从磁盘文件中载入。
BOOL LoadBitmap(UINT nIDResource)
HANDLE LoadImage(HINSTANCE hinst,LPCTSTR lpszName,UINT uType,int cxDesired,int cyDesired,UINT fuLoad)
显示:普通显示BitBlt,拉伸显示StretchBlt
BOOL BitBlt(HDC hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,HDC hdcSrc,int nXSrc,int nYSrc,DWORD dwRop)
BOOL StretchBlt(HDC hdcDest,int nXOriginDest,int nYOriginDest,int nWidthDest,int nHeightDest,HDC hdcSrc,int nXOriginSrc,int nYOriginSrc,int nWidthSrc,int nHeightSrcDWORD dwRop)