1、添加组件库,并重命名。在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")
#import "D:/Program Files/ArcGIS/com/esriDisplay.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR"),rename("RGB", "esriRGB"), rename("CMYK", "esriCMYK"),rename("ResetDC", "esriIResetDC"), rename("DrawText", "esriDrawText")
#import "D:/Program Files/ArcGIS/com/esriGeoDatabase.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR"), rename("IRow", "esriIRow"), rename("ICursor", "esriICursor")
#import "D:/Program Files/ArcGIS/com/esriCarto.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR"), rename("ITableDefinition", "esriITableDefinition"), rename("UINT_PTR", "esriUINT_PTR")
#pragma warning(pop)
2、添加状态栏窗格:在manfrm源文件中indicators数组中添加两个ID_SEPARATOR。
3、在mainfrm中添加,显示坐标函数
void CMainFrame::SetPaneText(int index, CString sText)
{
if (m_wndStatusBar)
{
m_wndStatusBar.SetPaneText(index,sText);
}
}
4、添加mapcomposer类并添加showmousecoord函数
void CMapComposer::showMouseCoord(double mapX,double mapY)
{
if(m_ipMap ==NULL) return;
HRESULT hr;
esriUnits eUnits;
CString sUnits;
BSTR bsUnits;
IUnitConverterPtr ipUC(CLSID_UnitConverter);
hr = m_ipMap->get_MapUnits(&eUnits);
if(FAILED(hr)) return;
hr = ipUC->EsriUnitsAsString(eUnits,esriCaseAppearanceUnchanged,VARIANT_FALSE,&bsUnits);
if(FAILED(hr)) return;
sUnits = bsUnits;
char tbuf[120];
sprintf(tbuf,"%.4f,%.4f,%s",mapX,mapY,sUnits);////这个函数写错了,编译不会出错!
CMainFrame * pMainFrm = (CMainFrame*)AfxGetMainWnd();
if(pMainFrm ==NULL) return;
pMainFrm->SetPaneText(1,(CString)tbuf);
}
5、在stdafx.h中包含mapcomposer.h,在view类中添加响应mousemove消息OnMapControl1MouseMove函数
void CtestView::OnMouseMoveMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
// TODO: 在此处添加消息处理程序代码
CMapComposer MapComposer;
MapComposer.m_ipMap = m_ctrlMap.get_Map();
MapComposer.showMouseCoord(mapX,mapY);
}