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
最新文章
- SAP CRM 性能小技巧
- CPU中断和轮询
- C语言回顾-结构体、枚举和文件
- css_01之基础属性、选择器
- html中拼接字符串问题
- redis动态修改参数配置
- oracle中between
- ubuntu server nginx 安装与配置
- STL学习小结
- php重载
- Haskell缩进规则
- shell常用命令的用法
- Ext4 MVC CRUD操作
- python 序列(list,tuple,str)基本操作
- TensorFlow框架(5)之机器学习实践
- 进到页面后input输入框自动获取焦点
- Matlab_ eval 批量定义变量
- Apache Solr 实现去掉重复的搜索结果
- mac技巧之常用的快键键
- 通过IntelliJ IDEA和Maven命令查看某个jar包是怎么引入的
热门文章
- [置顶] 遇到难题(bug)的解决方法心得
- Spark on Mesos: 搭建Mesos的一些问题
- openstack中Nova组件images的全部python API 汇总
- Ubuntu_开启root 登陆
- VC++ WIN32 sdk实现按钮自绘详解 之二(关键是BS_OWNERDRAW和WM_DRAWITEM)
- Lucene.Net 2.3.1开发介绍 —— 二、分词(五)
- 与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成
- [Android学习笔记]try-catch
- C语言数据结构----递归的应用(斐波拉契数列、汉诺塔、strlen的递归算法)
- JSP/Servlet-----charset 、pageEncoding差别