默认头像
路人甲
路人甲
  • 注册日期2006-10-07
  • 发帖数26
  • QQ
  • 铜币195枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1851回复:2

关于实现ICommand定制ArcMap命令的一个问题

楼主#
更多 发布于:2008-02-20 02:13

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,请大家帮我看看是哪里错了?

喜欢0 评分0
E-mail: liugy52@126.com QQ: 496798107
默认头像
卧底
卧底
  • 注册日期2004-04-18
  • 发帖数235
  • QQ
  • 铜币614枚
  • 威望2点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2008-02-21 15:32

.net

load tlb文件

个人专栏: https://zhuanlan.zhihu.com/c_165676639
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2006-10-07
  • 发帖数26
  • QQ
  • 铜币195枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2008-02-21 09:16
自己顶一下,大家帮我看看吧。
E-mail: liugy52@126.com QQ: 496798107
举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部