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