JefferyZhou

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

获取DC

1. 附带裁剪区域的DC获取方法,借助InvalidateRect()扩展无效矩形

hdc = BeginPaint (hwnd, &ps) ;
EndPaint (hwnd, &ps) ;
InvalidateRect (hwnd, NULL, TRUE) ;
2. 没有裁剪区域的DC获取方法,同时也不会让无效矩形变为有效,借助ValidateRect()更新有效矩形
hdc = GetDC (hwnd) ;//GetDC(NULL) 获取整个屏幕的设备句柄
ReleaseDC (hwnd, hdc) ;
ValidateRect (hwnd, NULL) ;
3. 整个窗口内容的设备句柄
hdc = GetWindowDC (hwnd) ;
ReleaseDC (hwnd, hdc) ;
4. 创建于窗口无关的设备句柄
hdc = CreateDC (pszDriver, pszDevice, pszOutput, pData) ;//hdc = CreateIC (TEXT ("DISPLAY"), NULL, NULL, NULL) ;
DeleteDC (hdc) ;
5. 创建内存设备句柄
hdcMem = CreateCompatibleDC (hdc) ;
DeleteDC (hdcMem) ;
6. 创建MetaFile
hdcMeta = CreateMetaFile (pszFilename) ;
hmf = CloseMetaFile (hdcMeta) ;

文本相关

SYSTEM_FONT

GetTextMetrics (hdc, &tm) ;
TextOut (hdc, x, y, psText, iLength) ;
SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;

滚动条
SetScrollRange (hwnd, iBar, iMin, iMax, bRedraw) ;
SetScrollPos (hwnd, iBar, iPos, bRedraw) ; //GetScrollRange, GetScrollPos
SetScrollInfo (hwnd, iBar, &si, bRedraw) ;
GetScrollInfo (hwnd, iBar, &si) ;//ScrollWindow 

窗口更新
UpdateWindow (hwnd) ;

GDI基本图形
  • 直线和曲线
  • 填入区域
  • 位图
  • 文字

GDI 其他部分
  • 映像模式和变换
  • Metafile
  • 绘图区域
  • 路径
  • 剪裁
  • 调色盘
  • 打印
设备内容查询
iValue = GetDeviceCaps (hdc, iIndex) ;

设备属性堆栈
idSaved = SaveDC (hdc) ;
RestoreDC (hdc, idSaved) ;

低级绘图操作
SetPixel (hdc, x, y, crColor) ;
crColor = GetPixel (hdc, x, y) ;
GetCurrentPositionEx (hdc, &pt) ;
MoveToEx (hdc, xBeg, yBeg, NULL) ;
LineTo (hdc, xEnd, yEnd) ;
Rectangle (hdc, xLeft, yTop, xRight, yBottom) ;//边界框函数
Ellipse (hdc, xLeft, yTop, xRight, yBottom) ;
RoundRect (hdc, xLeft, yTop, xRight, yBottom, xCornerEllipse, yCornerEllipse) ;
Arc(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd) ;
Chord(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd) ;
Pie(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd) ;
PolyBezier (hdc, apt, iCount) ;
PolyBezierTo (hdc, apt, iCount) ;

GDI 对象

逻辑画笔是六种GDI对象之一,其它五种是画刷、位图、区域、字体和调色盘。除了调色盘之外,这些对象都是通过SelectObject选进设备内容的。

在使用画笔等GDI对象时,应该遵守以下三条规则:

  • 最后要删除自己建立的所有GDI对象。
  • 当GDI对象正在一个有效的设备内容中使用时,不要删除它。
  • 不要删除现有对象。
hPen = CreatePen (iPenStyle, iWidth, crColor) ;
SetROP2 (hdc, iDrawMode) ;

画刷是一个8×8的位图

hBrush = CreateSolidBrush (crColor) ;
hBrush = CreateHatchBrush (iHatchStyle, crColor) ;//CreatePatternBrush , CreateDIBPatternBrushPt
hBrush = CreateBrushIndirect (&logbrush) ;

GDI 映像方式
SetMapMode (hdc, iMapMode) ;

矩形操作函数
FillRect (hdc, &rect, hBrush) ;
FrameRect (hdc, &rect, hBrush) ;
InvertRect (hdc, &rect) ;
SetRect (&rect, xLeft, yTop, xRight, yBottom) ;

OffsetRect (&rect, x, y) ;

InflateRect (&rect, x, y) ;

SetRectEmpty (&rect) ;

CopyRect (&DestRect, &SrcRect) ;

IntersectRect (&DestRect, &SrcRect1, &SrcRect2) ;

UnionRect (&DestRect, &SrcRect1, &SrcRect2) ;

bEmpty = IsRectEmpty (&rect) ;

bInRect = PtInRect (&rect, point) ;


建立和绘制裁剪区域
hRgn = CreateRectRgn (xLeft, yTop, xRight, yBottom) ;
hRgn = CreateRectRgnIndirect (&rect) ;
hRgn = CreateEllipticRgn (xLeft, yTop, xRight, yBottom) ;
hRgn = CreateEllipticRgnIndirect (&rect) ;
hRgn = CreatePolygonRgn (&point, iCount, iPolyFillMode) ;
iRgnType = CombineRgn (hDestRgn, hSrcRgn1, hSrcRgn2, iCombine) ;
FillRgn (hdc, hRgn, hBrush) ;        
FrameRgn (hdc, hRgn, hBrush, xFrame, yFrame) ;        
InvertRgn (hdc, hRgn) ;        
PaintRgn (hdc, hRgn) ;
DeleteObject (hRgn) ;
InvalidateRgn (hwnd, hRgn, bErase) ;
ValidateRgn (hwnd, hRgn) ;
SelectObject (hdc, hRgn) ;
SelectClipRgn (hdc, hRgn) ;
posted on 2012-09-24 17:14  JefferyZhou  阅读(2411)  评论(0编辑  收藏  举报