绘制带箭头的直线【MFC】
作者:互联网
有些参数还可以进行提取优化,目前只能算个雏形。
void drawArrow(CDC* pDC,CPoint start,CPoint end) {
double PI = acos(-1);
pDC->SelectObject(new CPen(PS_SOLID, 1, RGB(0, 0, 0)));
pDC->MoveTo(start);
pDC->LineTo(end);
CPoint l, r;
if (start.x == end.x) {
int y = 9;
if (end.y > start.y)y = -y;
CPoint right(end.x-5,end.y+y), left(end.x + 5, end.y + y);
l = left;
r = right;
}
else {
//获取斜率
double angle = atan(1.0*(end.y - start.y) / (end.x - start.x));
int rarrowx = end.x - 10 * cos(PI / 6 + angle);
int rarrowy = end.y - 10 * sin(PI / 6 + angle);
int larrowx = end.x - 10 * sin(PI / 3 + angle);
int larrowy = end.y + 10 * cos(PI / 3 + angle);
CPoint right(rarrowx, rarrowy), left(larrowx, larrowy);
l = left;
r = right;
}
pDC->MoveTo(r);
pDC->LineTo(end);
pDC->MoveTo(l);
pDC->LineTo(end);
}
标签:MFC,end,start,int,pDC,箭头,angle,PI,绘制 来源: https://www.cnblogs.com/sxrekord/p/draw_a_line_with_an_arrow.html