ICommand实现代码:(参考Creating a simple command for ArcMap -- from google search)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
namespace DemoCommand
{
[ClassInterface(ClassInterfaceType.None)]
[Guid("6CA23E75-01EC-4b28-9E12-B8BDC9FD21EC")]
[ProgId("Commands.DemoCommand")]
class ZoomIn : ICommand
{
#region Component Category Registration
[ComRegisterFunction]
[ComVisible(false)]
public static void RegisterFunction(Type t)
{
string sKey = @"\CLSID\{" + t.GUID.ToString() + @"}\Implemented Categories";
Microsoft.Win32.RegistryKey regKey
= Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(sKey, true);
if (regKey != null)
{
regKey.CreateSubKey("{6CA23E75-01EC-4b28-9E12-B8BDC9FD21EC}");
}
}
[ComUnregisterFunction]
[ComVisible(false)]
public static void UnregisterFunction(Type t)
{
string sKey = @"\CLSID\{" + t.GUID.ToString() + @"}\Implemented Categories";
Microsoft.Win32.RegistryKey regKey
= Microsoft.Win32.Registry.ClassesRoot
.OpenSubKey(sKey, true);
if (regKey != null)
{
regKey.DeleteSubKey("{6CA23E75-01EC-4b28-9E12-B8BDC9FD21EC}");
}
}
#endregion
[DllImport("gdi32.dll")]
static extern bool DeleteObject(IntPtr hObject);
private IntPtr m_bitmap;
private string m_caption;
private string m_category;
private bool m_checked;
private bool m_enabled;
private int m_helpContextID;
private string m_helpFile;
private string m_message;
private string m_name;
private string m_tooltip;
private IHookHelper m_hookHelper;
public ZoomIn()
{
Bitmap bitmap = new Bitmap(GetType().Assembly.GetManifestResourceStream
("DemoCommand.ZoomIn.bmp"));
if (bitmap != null)
{
bitmap.MakeTransparent(bitmap.GetPixel(1, 1));
m_bitmap = bitmap.GetHbitmap();
}
}
~ZoomIn()
{
if (m_bitmap.ToInt32() != 0)
DeleteObject(m_bitmap);
}
public void OnCreate(object hook)
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
}
public void OnClick()
{
IActiveView activeView = m_hookHelper.ActiveView;
IEnvelope currExtent = (IEnvelope)activeView.Extent;
currExtent.Expand(0.5D, 0.5D, true);
activeView.Extent = currExtent;
activeView.Refresh();
}
public int Bitmap
{
get
{
return m_bitmap.ToInt32();
}
}
public string Caption
{
get
{
return "Zoom In x 0.5 C#";
}
}
public string Category
{
get
{
return "Developer Samples";
}
}
public bool Checked
{
get
{
return false;
}
}
public bool Enabled
{
get
{
return m_enabled;
}
}
public int HelpContextID
{
get
{
return m_helpContextID;
}
}
public string HelpFile
{
get
{
return m_helpFile;
}
}
public string Message
{
get
{
return "Zooms the display to half the current extent.";
}
}
public string Name
{
get
{
return "Developer Samples_Zoom In C#";
}
}
public string Tooltip
{
get
{
return "Zoom In x 0.5 C#";
}
}
}
}
================================================================
在成功生成DLL后,在ArcMap工具栏定制对话框中从DLL添加Command时,却出现以下错误:
Can't load type library from specified file.
刚开始学ArcGIS,请大家帮我看看是哪里错了?