当前位置:首页 > 操作系统 > Windows

Win32 Windows编程 十

一 Windows画图

1 图形绘制

1.1 图形绘制的方式

获取到画图的句柄,设备描写叙述符(DC)。使用对应的画图API。在设备上绘制图形

1.2 颜色

RGB,每种颜色8位,共24位颜色

32位颜色:颜色数量24为颜色,多出的8位表示灰度。

16位:颜色数量是2的16次方。

Win32下。颜色的定义使用 COLORREF。RGB的宏定义颜色

COLORREF nColor = RGB( 0, 0, 0 );  黑色

COLORREF nColor = RGB( 255, 255, 255 ); 白色

COLORREF nColor = RGB( 255, 255, 255 ); 红色

从一个颜色值中获取RGB三色:

int  nRed = GetRValue( DWord rgb )

int nGreen = GetGValue( DWord rgb )

int nBlue = GetBVakue( DWord rgb )

1.3 点的绘制和获取

绘制: SetPixel

COLORREF SetPixel(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,    // handle to DC
  int<em><a href="" title="nXPos" ref="nofollow">nXPos</a></em>,  // x-coordinate of pixel
  int<em><a href="" title="nYPos" ref="nofollow">nYPos</a>,</em>   // y-coordinate of pixel
  COLORREF crColor // 颜色值
);

获取: GetPixel

COLORREF GetPixel(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,    // handle to DC
  int<em><a href="" title="nXPos" ref="nofollow">nXPos</a></em>,  // x-coordinate of pixel
  int<em><a href="" title="nYPos" ref="nofollow">nYPos</a></em>   // y-coordinate of pixel
);
1.4 直线的绘制

MoveToEx移动当前点到指定位置

LineTo 从当前点绘制之前到指定位置

1.5 弧的绘制

Arc和AngleArc提供不同的绘制弧的方式

BOOL AngleArc(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,            // handle to device context
  int<em><a href="" title="X" ref="nofollow">X</a></em>,              // x-coordinate of circle‘s center 圆心x坐标
  int<em><a href="" title="Y" ref="nofollow">Y</a></em>,              // y-coordinate of circle‘s center 圆心y坐标
  DWORD<em><a href="" title="dwRadius" ref="nofollow">dwRadius</a></em>,     // circle‘s radius <span />  园的半径
  FLOAT<em><a href="" title="eStartAngle" ref="nofollow">eStartAngle</a></em>,  // arc‘s start angle<span />開始角度
  FLOAT<em><a href="" title="eSweepAngle" ref="nofollow">eSweepAngle</a></em>   // arc‘s sweep angle<span />夹角<span />
);
<span>圆弧的分割方式</span>
<span>int SetArcDirection(</span>
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,           // handle to device context
  int<em><a href="" title="ArcDirection" ref="nofollow">ArcDirection</a></em>   // new arc direction
);
BOOL Arc(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,         // handle to device context
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,   // x-coord of rectangle‘s upper-left corner
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,    // y-coord of rectangle‘s upper-left corner
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>,  // x-coord of rectangle‘s lower-right corner
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em>, // y-coord of rectangle‘s lower-right corner 外切矩形的坐标
  int<em><a href="" title="nXStartArc" ref="nofollow">nXStartArc</a></em>,  // x-coord of first radial ending point
  int<em><a href="" title="nYStartArc" ref="nofollow">nYStartArc</a></em>,  // y-coord of first radial ending point
  int<em><a href="" title="nXEndArc" ref="nofollow">nXEndArc</a></em>,    // x-coord of second radial ending point
  int<em><a href="" title="nYEndArc" ref="nofollow">nYEndArc</a></em>     // y-coord of second radial ending point
);

1.6 折线

BOOL Polyline(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,            // handle to device context
  CONST POINT<em></em>*<em><a href="" title="lppt" ref="nofollow">lppt</a></em>,  // array of endpoints
  int<em><a href="" title="cPoints" ref="nofollow">cPoints</a></em>         // number of points in array
);
BOOL PolylineTo(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,            // handle to device context
  CONST POINT<em></em>*<em><a href="" title="lppt" ref="nofollow">lppt</a></em>,  // array of points
  DWORD<em><a href="" title="cCount" ref="nofollow">cCount</a></em>        // number of points in array
); 与PolyLine类似, 在绘制PolyLine前。从当前点使用LineTo绘制直线到Polyline的第一个顶点


BOOL PolyPolyline(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,                      // handle to device context
  CONST POINT<em></em>*<em><a href="" title="lppt" ref="nofollow">lppt</a></em>,            // array of points   全部点的数组
  CONST DWORD<em></em>*<em><a href="" title="lpdwPolyPoints" ref="nofollow">lpdwPolyPoints</a></em>,  // array of values    每组点的数量  <span />
  DWORD<em><a href="" title="cCount" ref="nofollow">cCount</a></em>                  // number of entries in values array 分组的数量
);

1.7 Bizer曲线

BOOL PolyBezier(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,            // handle to device context
  CONST POINT* <em><a href="" title="lppt" ref="nofollow">lppt</a></em>,  // endpoints and control points 点数组
  DWORD<em><a href="" title="cPoints" ref="nofollow">cPoints</a></em>       // count of endpoints and control points 点的数量
);

1.8 圆角矩形

BOOL RoundRect(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,         // handle to DC
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,   // x-coord of upper-left corner of rectangle
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,    // y-coord of upper-left corner of rectangle
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>,  // x-coord of lower-right corner of rectangle
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em>, // y-coord of lower-right corner of rectangle
  int<em><a href="" title="nWidth" ref="nofollow">nWidth</a></em>,      // width of ellipse 生成圆角的椭圆的宽度
  int<em><a href="" title="nHeight" ref="nofollow">nHeight</a></em>      // height of ellipse 生成圆角的椭圆的高度
);
1.9 矩形
BOOL Rectangle(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,         // handle to DC
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,   // x-coord of upper-left corner of rectangle
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,    // y-coord of upper-left corner of rectangle
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>,  // x-coord of lower-right corner of rectangle
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em>  // y-coord of lower-right corner of rectangle
);
1.10 椭圆
BOOL Ellipse(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,        // handle to DC
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,  // x-coord of upper-left corner of rectangle
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,   // y-coord of upper-left corner of rectangle
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>, // x-coord of lower-right corner of rectangle
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em> // y-coord of lower-right corner of rectangle
);
1.11 pie饼
BOOL Pie(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,         // handle to DC
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,   // x-coord of upper-left corner of rectangle
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,    // y-coord of upper-left corner of rectangle
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>,  // x-coord of lower-right corner of rectangle
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em>, // y-coord of lower-right corner of rectangle
  int<em><a href="" title="nXRadial1" ref="nofollow">nXRadial1</a></em>,   // x-coord of first radial‘s endpoint
  int<em><a href="" title="nYRadial1" ref="nofollow">nYRadial1</a></em>,   // y-coord of first radial‘s endpoint
  int<em><a href="" title="nXRadial2" ref="nofollow">nXRadial2</a></em>,   // x-coord of second radial‘s endpoint
  int<em><a href="" title="nYRadial2" ref="nofollow">nYRadial2</a></em>    // y-coord of second radial‘s endpoint
);
1.12 弦
BOOL Chord(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,         // handle to DC
  int<em><a href="" title="nLeftRect" ref="nofollow">nLeftRect</a></em>,   // x-coord of upper-left corner of rectangle
  int<em><a href="" title="nTopRect" ref="nofollow">nTopRect</a></em>,    // y-coord of upper-left corner of rectangle
  int<em><a href="" title="nRightRect" ref="nofollow">nRightRect</a></em>,  // x-coord of lower-right corner of rectangle
  int<em><a href="" title="nBottomRect" ref="nofollow">nBottomRect</a></em>, // y-coord of lower-right corner of rectangle
  int<em><a href="" title="nXRadial1" ref="nofollow">nXRadial1</a></em>,   // x-coord of first radial‘s endpoint
  int<em><a href="" title="nYRadial1" ref="nofollow">nYRadial1</a></em>,   // y-coord of first radial‘s endpoint
  int<em><a href="" title="nXRadial2" ref="nofollow">nXRadial2</a></em>,   // x-coord of second radial‘s endpoint
  int<em><a href="" title="nYRadial2" ref="nofollow">nYRadial2</a></em>    // y-coord of second radial‘s endpoint
);
1.13 多变形
BOOL Polygon(
  HDC<em><a href="" title="hdc" ref="nofollow">hdc</a></em>,                // handle to DC
  CONST POINT<em></em>*<em><a href="" title="lpPoints" ref="nofollow">lpPoints</a></em>,  // polygon vertices
  int<em><a href="" title="nCount" ref="nofollow">nCount</a></em>              // count of polygon vertices
);

2 GDI画图对象 - 画笔

2.1 画笔的作用

能够控制线条的颜色、样式、宽度

 2.2 画笔的使用

创建画笔

CreatePen

置成当前DC能够使用的画笔

SelectObject

绘制图形

从当前DC中取出画笔

SelectObject 

销毁画笔

DeleteObject

3 GDI画图对象 - 画刷

3.1 画刷的作用

填充封闭图形,包含样式 颜色

3.2 画刷的使用

创建画刷

CreateSilidBrush

CreateHatchBrush

置成当前DC能够使用的画刷

SelectObject

绘制图形

取出画刷

SelectObject

销毁画刷

DeleteObject












原文:http://www.cnblogs.com/lcchuguo/p/5087647.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐