码迷,mamicode.com
首页 > 编程语言 > 详细

MFC画带箭头的直线

时间:2015-11-10 09:20:04      阅读:769      评论:0      收藏:0      [点我收藏+]

标签:

构造一个函数,是在startPoint,endPoint间画一条带箭头的线段:
void CTry1View::DrawLine(POINT startPoint, POINT endPoint)
{
CClientDC dc(this);
dc.MoveTo(startPoint);
dc.LineTo(endPoint);

double PI = 3.1415926;
double t=PI/4; //箭头与直线夹角
double l=0.2; //箭头边长度占直线长度的百分比

POINT arrowPoint;

arrowPoint.x = (int)(l*((startPoint.x-endPoint.x)*cos(t)-(startPoint.y-endPoint.y)*sin(t))+endPoint.x);
arrowPoint.y = (int)(l*((startPoint.x-endPoint.x)*sin(t)+(startPoint.y-endPoint.y)*cos(t))+endPoint.y);
dc.MoveTo(endPoint);
dc.LineTo(arrowPoint);

arrowPoint.x = (int)(l*((startPoint.x-endPoint.x)*cos(-t)-(startPoint.y-endPoint.y)*sin(-t))+endPoint.x);
arrowPoint.y = (int)(l*((startPoint.x-endPoint.x)*sin(-t)+(startPoint.y-endPoint.y)*cos(-t))+endPoint.y);
dc.MoveTo(endPoint);
dc.LineTo(arrowPoint);
}

 

MFC画带箭头的直线

标签:

原文地址:http://www.cnblogs.com/Decmber/p/4951871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!