自己添加放大(zoomout),缩小(zoomin),全图(fullextent),漫游(pan)

在上一次程序基础上进行此操作;

1、删除toolbarcontrl及连接,即设置的buddy。

2、在菜单栏及工具栏添加这几个工具菜单,本想只做个工具栏按钮,在vc++2005中找不到直接添加消息的菜单,谁知道请教了,

     添加消息响应函数,实现这既给函数

void CtestView::OnViewFullview()
{
 m_ctrlMap.get_FullExtent();
 // TODO: 在此添加命令处理程序代码
}

void CtestView::OnViewPan()
{
 m_eCurView = eViewPan;
 m_ctrlMap.put_MousePointer(53);
 // TODO: 在此添加命令处理程序代码
}

void CtestView::OnViewZoomin()
{
 m_eCurView = eViewZoomIn;
 m_ctrlMap.put_MousePointer(51);
 // TODO: 在此添加命令处理程序代码
}

void CtestView::OnViewZoomout()
{
 m_eCurView = eViewZoomOut;
 m_ctrlMap.put_MousePointer(52);
 // TODO: 在此添加命令处理程序代码
}
3、由于要使用AE组件库,在arcgis安装目录下import文件,并重命名,据说是跟c库有冲突,如果不重命名的话会出现错误。下面代码添加至StdAfx.h中:

#pragma warning(push)
#pragma warning(disable:4192)
#pragma warning(disable:4146)
#pragma warning(disable:4099)
#import "D:/Program Files/ArcGIS/com/esriSystem.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR")
#import "D:/Program Files/ArcGIS/com/esriSystemUI.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR"),rename("ICommand", "esriICommand"), rename("IProgressDialog", "esriIProgressDialog")
#import "D:/Program Files/ArcGIS/com/esriGeometry.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR")
#pragma warning(pop)
4.在view类中,编辑OnMouseDownMapcontrol1()函数,代码:

void CtestView::OnMouseDownMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
 // TODO: 在此处添加消息处理程序代码
 HRESULT hr;
 switch(m_eCurView)
 {
 case eViewZoomIn:
  m_ctrlMap.put_Extent(m_ctrlMap.TrackRectangle());
  break;
 case eViewZoomOut:
  {
   IEnvelopePtr ipCurExt,ipTrkExt,ipNewExt;
   double xC1,xC2,yC1,yC2,xT1,xT2,yT1,yT2,xN1,xN2,yN1,yN2;
   ipCurExt = m_ctrlMap.get_Extent();
   ipTrkExt = m_ctrlMap.TrackRectangle();
   hr = ipCurExt->QueryCoords(&xC1,&yC1,&xC2,&yC2);
   if(FAILED(hr)) goto FAILED;
   hr = ipTrkExt->QueryCoords(&xT1,&yT1,&xT2,&yT2);
   if(FAILED(hr)) goto FAILED;
   xN1 = xC1 - (xT1 - xC1)*((xC2 - xC1)/(xT2 - xT1));
   yN1 = yC1 - (yT1 - yC1)*((yC2 - yC1)/(yT2 - yT1));
   xN2 = xC2 - (xT2 - xC2)*((xC2 - xC1)/(xT2 - xT1));
   yN2 = yC1 - (yT2 - yC2)*((yC2 - yC1)/(yT2 - yT1));
   hr = ipNewExt.CreateInstance(__uuidof(Envelope));
   if (FAILED(hr))  goto FAILED;
   hr = ipNewExt->PutCoords(xN1,yN1,xN2,yN2);
   if (FAILED(hr))  goto FAILED;
   m_ctrlMap.put_Extent(ipNewExt);
  }
  break;
 case eViewPan:
  m_ctrlMap.Pan();
  break;
 default:
  break;

 }
 return;
FAILED:
 AfxMessageBox(L"意外错误");
}

你可能感兴趣的:(c,import,工具,button,Types)