MFC中实现的画箭头算法 (Arrow in MFC)
可以改变三角形大小,顶点角度,是否填充和填充颜色等
但是画出的箭头还是不够美观....呵呵,还好吧
其中填充是代表箭头内是否填充颜色
先来看声明和实现
- //使用一个结构体来存储相关的信息
- //Defines the attributes of an arrow.
- typedef struct tARROWSTRUCT {
- int nWidth; // width (in pixels) of the full base of the arrowhead
- float fTheta; // angle (in radians) at the arrow tip between the two
- // sides of the arrowhead
- bool bFill; // flag indicating whether or not the arrowhead should be
- // filled
- } ARROWSTRUCT;
- ///
- //函数声明
- // Draws an arrow, using the current pen and brush, from the current position
- // to the passed point using the attributes defined in the ARROWSTRUCT.
- void ArrowTo(HDC hDC, int x, int y, ARROWSTRUCT *pArrow);
- void ArrowTo(HDC hDC, const POINT *lpTo, ARROWSTRUCT *pArrow);
- ///
- //画箭头函数实现
- void CMyDialog::ArrowTo(HDC hDC, int x, int y, ARROWSTRUCT *pA) {
- POINT ptTo = {x, y};
- ArrowTo(hDC, &ptTo, pA);
- }
- void CMyDialog::ArrowTo(HDC hDC, const POINT *lpTo, ARROWSTRUCT *pA) {
- POINT pFrom;
- POINT pBase;
- POINT aptPoly[3];
- float vecLine[2];
- float vecLeft[2];
- float fLength;
- float th;
- float ta;
- // get from point
- MoveToEx(hDC, 0, 0, &pFrom);
- // set to point
- aptPoly[0].x = lpTo->x;
- aptPoly[0].y = lpTo->y;
- // build the line vector
- vecLine[0] = (float) aptPoly[0].x - pFrom.x;
- vecLine[1] = (float) aptPoly[0].y - pFrom.y;
- // build the arrow base vector - normal to the line
- vecLeft[0] = -vecLine[1];
- vecLeft[1] = vecLine[0];
- // setup length parameters
- fLength = (float) sqrt(vecLine[0] * vecLine[0] + vecLine[1] * vecLine[1]);
- th = pA->nWidth / (2.0f * fLength);
- ta = pA->nWidth / (2.0f * (tanf(pA->fTheta) / 2.0f) * fLength);
- // find the base of the arrow
- pBase.x = (int) (aptPoly[0].x + -ta * vecLine[0]);
- pBase.y = (int) (aptPoly[0].y + -ta * vecLine[1]);
- // build the points on the sides of the arrow
- aptPoly[1].x = (int) (pBase.x + th * vecLeft[0]);
- aptPoly[1].y = (int) (pBase.y + th * vecLeft[1]);
- aptPoly[2].x = (int) (pBase.x + -th * vecLeft[0]);
- aptPoly[2].y = (int) (pBase.y + -th * vecLeft[1]);
- MoveToEx(hDC, pFrom.x, pFrom.y, NULL);
- // draw we're fillin'...
- if(pA->bFill) {
- LineTo(hDC, aptPoly[0].x, aptPoly[0].y);
- Polygon(hDC, aptPoly, 3);
- }
- // ... or even jes chillin'...
- else {
- LineTo(hDC, pBase.x, pBase.y);
- LineTo(hDC, aptPoly[1].x, aptPoly[1].y);
- LineTo(hDC, aptPoly[0].x, aptPoly[0].y);
- LineTo(hDC, aptPoly[2].x, aptPoly[2].y);
- LineTo(hDC, pBase.x, pBase.y);
- MoveToEx(hDC, aptPoly[0].x, aptPoly[0].y, NULL);
- }
- }
再来看调用实现(加一层封装更加适用)
- /
- //封装调用函数实现(其实还是有很大的扩展空间的)
- void CMyDialog::ArrowTo(
- CDC *pDC, //画刷
- CPoint point, //终点坐标
- int nPenStyle, //线样式
- int nPenWidth, //线宽度
- COLORREF color, //颜色
- int nWidth, //三角形底边宽度
- float fTheta, //三角形顶角角度
- bool bFill //是否填充颜色
- )
- {
- ARROWSTRUCT a;
- a.nWidth = nWidth; //三角形底边宽度
- a.fTheta = fTheta; //三角形顶角角度
- a.bFill = bFill; //是否填充颜色
- CPen* pOldPen;
- CPen pen(nPenStyle,nPenWidth,color);
- pOldPen = pDC->SelectObject(&pen);
- CBrush br,*pbrOld;
- br.CreateSolidBrush(color);
- pbrOld = pDC->SelectObject(&br);
- ArrowTo(*pDC,point.x,point.y,&a); //调用画箭头函数
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pbrOld);
- }
转载于:https://www.cnblogs.com/wupingzsf/archive/2010/05/16/1736958.html
MFC中实现的画箭头算法 (Arrow in MFC)相关推荐
- 在MFC中,运用轨迹球算法实现鼠标旋转物体
参考资料:nehe教程第48课<轨迹球实现的鼠标旋转> 1.在头文件中为Arcball添加变量 //为Arcball添加变量用来获取当前鼠标点Point2fT MousePt;// NEW ...
- ATL--创建简单的ATL之dll工程,添加类和类的接口并在MFC中调用
资源打包 开发环境 Windows Server 2012 VS2010 Sp1 番茄助手 创建ATL简单dll工程 1.打开VS2010,新建ATL COM 项目,步骤:"文件" ...
- mfc中插入PNG透明图片
mfc中插入PNG透明图片 记录下在mfc中插入png透明图片的方法 新建项目 在对话框界面中插入两个 Picture Control 在MFC_pngDlg.h中添加 在MFC_pngDlg.cpp ...
- 修改MFC中AfxMessageBox()函数的对话框标题
修改MFC中AfxMessageBox()函数的对话框标题 如何在MFC中修改AfxMessageBox()函数所弹出的对话框标题,步骤如下: 1.找到项目工程的资源视图,打开.rc资源文件下的Str ...
- 【opencv】3.在一个opencv窗口中显示多个视频界面、画箭头、画掉头箭头
1.在一个opencv窗口中显示不同视频界面 /** * @brief 在一个opencv窗口win_name中显示不同视频界面 * @param img_1 和 img_2 是分别是取自不同视频中的 ...
- mfc 画圆算法 画椭圆算法
mfc画圆算法 求半径:圆心一点:m_ptOrigin1,圆上一点:m_ptOrigin2 注释:这里的m_ptOrigin1,m_ptOrigin2均为Cpoint类型 R=int(sqrt(pow ...
- 中点Bresenham画圆算法|MFC|计算机图形学
中点Bresenham画圆算法|MFC|计算机图形学 Bresenham中点画圆算法 计算机图形学-基本图元的生成-圆 基于学习直线的生成算法后,又展开了圆.椭圆的讲解: 此次试验是简单的MFC应用, ...
- MFC中的控件是怎么实现的呢?一个按钮就是一个窗口?还是所有按钮画在一个分层窗口上再叠
请教一下MFC中的控件是怎么实现的呢(通过调用什么样的API,传递什么参数)?一个按钮就是一个窗口?还是所有按钮画在一个分层窗口上再叠在主窗口上?还是直接在主窗口上画图? 我想到的是: JavaScr ...
- matlab 中画箭头
matlab 画图时,没有直接画箭头的函数.网上搜索解决方案时,有人提到用 annotation 函数,但该函数的位置坐标并不是传统的坐标值,而是在整个图形位置的单位坐标,不好调整:另一种方法 用 f ...
最新文章
- “静态常量”与“ #define”与“枚举”
- Oracle创建触发器的普通应用
- linux上安装配置vsftpd
- Backup Exec for Windows Servers (BEWS) 简体中文文档汇总(持续更新)
- Debian Security Advisory(Debian安全报告) DSA-4411-1 firefox-esr security update
- (pytorch-深度学习)深度循环神经网络
- 哈工大未来计算机院士,2017年中国高校新增工程院院士名单出炉,哈工大依然很强!...
- helm安装_如何利用 Helm 在 Kubernetes 上快速部署 Jenkins
- c 连接mysql数据库查询_C语言实现访问及查询MySQL数据库的方法
- php数据库随机选择,php – 在MySQL数据库中选择两个随机行
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
- 系统架构设计师与系统分析师历年实体分析与解答下载_架构设计的本质
- 什么是互联网外包公司
- web前端入门到实战:img中alt和title属性的区别
- web网站整体变灰色仅仅需要两行代码
- 小提琴统计图_快速绘制分组小提琴图工具
- JVM之运行时数据区(方法区)
- 把你的阿里巴巴图标库转成你自己的@ant-design/icons
- 7、Callable接口
- Race_Condition实验
热门文章
- LeetCode 1072. 按列翻转得到最大值等行数(查找相同的模式,哈希计数)
- LeetCode 491. 递增子序列(回溯+判重剪枝)
- LeetCode 98. 验证二叉搜索树(中序遍历)
- java impala_Java实现impala操作kudu
- 利用python批量修改文件名称
- python中的字符串操作及注意事项
- python混沌时间序列分析_用Python进行时间序列分析
- java私有表示标识_java里面的标识符、关键字和类型
- python odoo_odoo python 使用缓存
- python清除列表内容_Python 列表的清空方式