CSDN博客

img yesgis

mapx之vc自定义测距工具(PolyToolUsed事件)

发表于2004/4/26 10:52:00  1106人阅读

【功能】:mapx之vc自定义测距工具(PolyToolUsed事件)
【环境】:VC6+mapx4.5+win2000
【原创】: www.51gis.com

//1.定义常量
#define MYTOOL_DISTANCE 100 //1~999

//2.创建工具
m_ctrlMap.CreateCustomTool(MYTOOL_DISTANCE,miToolTypePoly,miCrossCursor);

//3.响应事件
void CMapXSampleView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points,
BOOL bShift,BOOL bCtrl,BOOL FAR* EnableDefault)
{
//计算距离
if(Flags==miPolyToolInProgress) {//这句可有可无
if(ToolNum==MYTOOL_DISTANCE)
{
CMapXPoints pts;
long n;
long i;
try{
pts.AttachDispatch (Points, FALSE); // Get points Object
double dDistanceTot=0.0;
n=pts.GetCount ();
for (i=1; i<n;i++)
{
CMapXPoint pt1=pts.Item(i);
CMapXPoint pt2=pts.Item(i+1);
double d=m_ctrlMapX.Distance (pt1.GetX(),pt1.GetY(),pt2.GetX (),
pt2.GetY ());
dDistanceTot+=d;
}
CString str;
str.Format ("总距离为:%f",dDistanceTot);
//在状态栏输出距离
((CMainFrame*)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0,str);
}
catch (COleDispatchException *e){
e->ReportError ();
e->Delete ();
}
catch (COleException *e){
e->ReportError ();
e->Delete ();
}
}
}//if(Flags==miPolyToolInProgress)
}

//4.调用工具
void CMapXSampleView::OnMapToolDistancetool()
{
m_ctrlMapX.SetCurrentTool(MYTOOL_DISTANCE); //

}

==================MapX专家论坛(www.51gis.com)===================

0 0

相关博文

我的热门文章

img
取 消
img