Win32 Windows编程 十

来源:互联网 发布:有福气的八字 知乎 编辑:程序博客网 时间:2024/06/09 22:12

一 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 hdc,    // handle to DC  int nXPos,  // x-coordinate of pixel  int nYPos,   // y-coordinate of pixel
  COLORREF crColor // 颜色值
);

获取: GetPixel

COLORREF GetPixel(  HDC hdc,    // handle to DC  int nXPos,  // x-coordinate of pixel  int nYPos   // y-coordinate of pixel);
1.4 直线的绘制

MoveToEx移动当前点到指定位置

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

1.5 弧的绘制

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

BOOL AngleArc(  HDC hdc,            // handle to device context  int X,              // x-coordinate of circle's center 圆心x坐标  int Y,              // y-coordinate of circle's center 圆心y坐标  DWORD dwRadius,     // circle's radius   园的半径  FLOAT eStartAngle,  // arc's start angle开始角度  FLOAT eSweepAngle   // arc's sweep angle夹角);

圆弧的切割方式
int SetArcDirection(
  HDC hdc,           // handle to device context  int ArcDirection   // new arc direction);
BOOL Arc(  HDC hdc,         // handle to device context  int nLeftRect,   // x-coord of rectangle's upper-left corner  int nTopRect,    // y-coord of rectangle's upper-left corner  int nRightRect,  // x-coord of rectangle's lower-right corner  int nBottomRect, // y-coord of rectangle's lower-right corner 外切矩形的坐标  int nXStartArc,  // x-coord of first radial ending point  int nYStartArc,  // y-coord of first radial ending point  int nXEndArc,    // x-coord of second radial ending point  int nYEndArc     // y-coord of second radial ending point);

1.6 折线

BOOL Polyline(  HDC hdc,            // handle to device context  CONST POINT *lppt,  // array of endpoints  int cPoints         // number of points in array);

BOOL PolylineTo(  HDC hdc,            // handle to device context  CONST POINT *lppt,  // array of points  DWORD cCount        // number of points in array); 与PolyLine类似, 在绘制PolyLine前,从当前点使用LineTo绘制直线到Polyline的第一个顶点


BOOL PolyPolyline(  HDC hdc,                      // handle to device context  CONST POINT *lppt,            // array of points   所有点的数组  CONST DWORD *lpdwPolyPoints,  // array of values    每组点的数量    DWORD cCount                  // number of entries in values array 分组的数量);

1.7 Bizer曲线

BOOL PolyBezier(  HDC hdc,            // handle to device context  CONST POINT* lppt,  // endpoints and control points 点数组  DWORD cPoints       // count of endpoints and control points 点的数量
);

1.8 圆角矩形

BOOL RoundRect(  HDC hdc,         // handle to DC  int nLeftRect,   // x-coord of upper-left corner of rectangle  int nTopRect,    // y-coord of upper-left corner of rectangle  int nRightRect,  // x-coord of lower-right corner of rectangle  int nBottomRect, // y-coord of lower-right corner of rectangle  int nWidth,      // width of ellipse 生成圆角的椭圆的宽度  int nHeight      // height of ellipse 生成圆角的椭圆的高度);
1.9 矩形

BOOL Rectangle(  HDC hdc,         // handle to DC  int nLeftRect,   // x-coord of upper-left corner of rectangle  int nTopRect,    // y-coord of upper-left corner of rectangle  int nRightRect,  // x-coord of lower-right corner of rectangle  int nBottomRect  // y-coord of lower-right corner of rectangle);
1.10 椭圆

BOOL Ellipse(  HDC hdc,        // handle to DC  int nLeftRect,  // x-coord of upper-left corner of rectangle  int nTopRect,   // y-coord of upper-left corner of rectangle  int nRightRect, // x-coord of lower-right corner of rectangle  int nBottomRect // y-coord of lower-right corner of rectangle);
1.11 pie饼

BOOL Pie(  HDC hdc,         // handle to DC  int nLeftRect,   // x-coord of upper-left corner of rectangle  int nTopRect,    // y-coord of upper-left corner of rectangle  int nRightRect,  // x-coord of lower-right corner of rectangle  int nBottomRect, // y-coord of lower-right corner of rectangle  int nXRadial1,   // x-coord of first radial's endpoint  int nYRadial1,   // y-coord of first radial's endpoint  int nXRadial2,   // x-coord of second radial's endpoint  int nYRadial2    // y-coord of second radial's endpoint);
1.12 弦

BOOL Chord(  HDC hdc,         // handle to DC  int nLeftRect,   // x-coord of upper-left corner of rectangle  int nTopRect,    // y-coord of upper-left corner of rectangle  int nRightRect,  // x-coord of lower-right corner of rectangle  int nBottomRect, // y-coord of lower-right corner of rectangle  int nXRadial1,   // x-coord of first radial's endpoint  int nYRadial1,   // y-coord of first radial's endpoint  int nXRadial2,   // x-coord of second radial's endpoint  int nYRadial2    // y-coord of second radial's endpoint);
1.13 多变形

BOOL Polygon(  HDC hdc,                // handle to DC  CONST POINT *lpPoints,  // polygon vertices  int nCount              // 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












0 0