在codeproject中寻找到一个这样的算法,在这里介绍一下
可以改变三角形大小,顶点角度,是否填充和填充颜色等
但是画出的箭头还是不够美观....呵呵,还好吧
其中填充是代表箭头内是否填充颜色
先来看声明和实现
//使用一个结构体来存储相关的信息
//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;