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 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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值