資源簡介
c++ code for drawing arrows in any CDC

代碼片段和文件信息
#include?“Arrow.h“
#include?
//?ArrowTo()
//
void?ArrowTo(HDC?hDC?int?x?int?y?ARROWSTRUCT?*pA)?{
POINT?ptTo?=?{x?y};
ArrowTo(hDC?&ptTo?pA);
}
//?ArrowTo()
//
void?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);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1831??2002-12-01?14:29??Arrow.cpp
?????文件?????????743??2002-12-01?14:28??Arrow.h
?????文件????????3726??2002-12-01?12:59??ArrowTest.cpp
?????文件????????4664??2002-12-01?14:26??ArrowTest.dsp
?????文件?????????541??2002-12-01?12:59??ArrowTest.dsw
?????文件????????1400??2002-12-01?12:59??ArrowTest.h
?????文件????????8739??2002-12-01?12:59??ArrowTest.rc
?????文件????????1721??2002-12-01?14:29??ChildView.cpp
?????文件????????1267??2002-12-01?12:59??ChildView.h
?????文件????????3286??2002-12-01?12:59??MainFrm.cpp
?????文件????????1744??2002-12-01?12:59??MainFrm.h
?????目錄???????????0??2002-12-01?12:59??res\
?????文件????????1078??2002-12-01?12:59??res\ArrowTest.ico
?????文件?????????401??2002-12-01?12:59??res\ArrowTest.rc2
?????文件?????????718??2002-12-01?12:59??res\Toolbar.bmp
?????文件?????????497??2002-12-01?12:59??Resource.h
?????文件?????????211??2002-12-01?12:59??StdAfx.cpp
?????文件????????1054??2002-12-01?12:59??StdAfx.h
- 上一篇:Kinect2.0+PCL實現點云顯示
- 下一篇:地球儀紋理型紋理貼圖 C++代碼
評論
共有 條評論