这个过程就是制作ArcMap插件的过程,说实话挺恶心的,为什么不用VS2013呢 ? 主要是环境有问题 。
Go! Let‘s do it!
一、 新建ATL项目 (项目命名Demo即可)
第二步 直接点完成、无需修改当中项:
第三步 右键当前项目Demo 添加类
选择“ATL简单对象”
点击添加 而后命名ZoomIn 简洁明白大方:
然后在接口处选择“自定义” 主要是为了后面实现ICommand接口
完成即可;
而后对Demo.idl 部分修改:
接下来是引入esri对象库文件(在stdafx.h当中引入):
#pragma warning(push)
#pragma warning(disable : 4192)
//disables warning: automatically excluding 'name' while importing type library 'library'
//import esriSystem.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriSystem.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE", "XMLSerializer") rename("min","esrimin") rename("max","esrimax") rename("GetObject","esriGetObject") rename("GetJob","esriGetJob")
//import esriSystemUI.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriSystemUI.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_HANDLE", "OLE_COLOR")
//import esriGeometry.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriGeometry.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_HANDLE", "OLE_COLOR", "ISegment")
//import esriDisplay.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriDisplay.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_HANDLE", "OLE_COLOR") rename("RGB","esriRGB") rename("DrawText","esriDrawText") rename("ResetDC","esriResetDC") rename("CMYK","esriCMYK")
//import esriGeoDatabase.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriGeoDatabase.olb" raw_interfaces_only raw_native_types no_namespace named_guids rename("GetMessage","esriGetMessage")
//import esriCarto.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriCarto.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("UINT_PTR") rename("PostMessage","esriPostMessage")
//import esriControls.olb
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriControls.olb" raw_interfaces_only raw_native_types no_namespace named_guids rename("DrawText","esriDrawText")
#import "C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriSystemUI.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search
#import "C:\Program Files (x86)\ArcGIS\Engine10.2\com\esriSystemUI.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search
#pragma warning(pop)
然后转到类视图 右键CZoomIn ------> 添加 -----> 实现接口 (ICommand接口)
完成即可;
接下来就是对这些方法进行实现
转到ZoomIn.h 删除原因的方法块:
转到ZoomIn.cpp去实现这些方法
// ZoomIn.cpp : CZoomIn 的实现
#include "stdafx.h"
#include "ZoomIn.h"
// CZoomIn
IHookHelperPtr m_ipHookHelper;
STDMETHODIMP CZoomIn::get_Enabled(VARIANT_BOOL *Enabled)
{
if (Enabled == NULL)
return E_POINTER;
*Enabled = VARIANT_TRUE; // Enable the tool always
return S_OK;
}
CZoomIn::CZoomIn()
{
m_hBitmap = ::LoadBitmap(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP1));
}
STDMETHODIMP CZoomIn::get_Name(BSTR *Name)
{
if (Name == NULL)
return E_POINTER;
*Name = ::SysAllocString(L"ZoomInDu");
return S_OK;
}
STDMETHODIMP CZoomIn::get_Caption(BSTR *Caption)
{
if (Caption == NULL)
return E_POINTER;
*Caption = ::SysAllocString(L"ZoomIn*Du");
return S_OK;
}
STDMETHODIMP CZoomIn::get_Category(BSTR *Category)
{
if (Category == NULL)
return E_POINTER;
*Category = ::SysAllocString(L"GisTools");
return S_OK;
}
STDMETHODIMP CZoomIn::get_Bitmap(OLE_HANDLE *Bitmap)
{
if (Bitmap == NULL)
return E_POINTER;
*Bitmap = (OLE_HANDLE)m_hBitmap;
return S_OK;
}
STDMETHODIMP CZoomIn::OnCreate(IDispatch *hook)
{
m_ipHookHelper.CreateInstance(CLSID_HookHelper);
HRESULT hr = m_ipHookHelper->putref_Hook(hook);
return hr;
}
STDMETHODIMP CZoomIn::OnClick()
{
// HRESULT checking omitted for clarity
IActiveViewPtr ipActiveView;
m_ipHookHelper->get_ActiveView(&ipActiveView);
IEnvelopePtr ipEnv;
ipActiveView->get_Extent(&ipEnv);
ipEnv->Expand(0.5, 0.5, VARIANT_TRUE);
ipActiveView->put_Extent(ipEnv);
ipActiveView->Refresh();
return S_OK;
}
最后去注册 在ZoomIn.h当中
然后设置启动程序 在项目右键属性 调试 选择ArcMap.EXE作为启动程序即可。
而后启动调试
自定义----》 从文件添加 选择dll即可
现在ok了~ 可以添加工具在菜单栏即可使用。。