使用VB.net和VB编写DLL组件的方法

这篇博客详细介绍了如何使用VB和VB.NET来编写DLL组件,特别适用于ESRI的AO开发。在VB中,需要创建ACTIVE DLL组件项目,引用ESRI Core objects,并实现ICommand接口的所有属性和方法。而在VB.NET中,创建VB类库项目,直接引用AO的.NET命名空间,通过ComClass特性来定义接口。两种方法都包括了示例代码,展示了如何处理DLL组件的创建、启用条件以及点击事件等。
摘要由CSDN通过智能技术生成

使用ESRI 的AO进行开发的时候,最常用的开发手段之一就是写DLL组件,使用VB或者VB.NET编写DLL组件的方法是不一样的。写DLL的时候,就是继承某个接口,而接口里面的方法和属性必须完全实现,不能够有任何的遗漏。以下便是VB和VB.NET开发AO的方法:

1.使用VB写DLL
使用一个Icommand或者Itool来写DLL组件,例子如下:
1.1在VB中开始一个ACTIVE DLL组件项目
1.2使用 工程--引用,引用ESRI Core objects
1.3代码如下:

Option Explicit
' 实现ICommand interface
Implements ICommand

Dim m_pApp As IApplication      'ArcMap application

Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE
  ' The VB project contains a form called Form1.
  ' Picture1 is the name of a PictureBox control on the form.
  ' The Picture property of PictureBox1 is set to some bitmap on
  ' your system.
  ICommand_Bitmap = Form1.Picture1.Picture.Handle
End Property

Private Property Get ICommand_Caption() As String
  ' Set the string that appears when the command is used as a
  ' menu item.
  ICommand_Caption = "MyCommand"
End Property

Private Property Get ICommand_Category() As String
  ' Set the category of this command. This determines where the
  ' command appears in the Commands panel of the Customize dialog.
  ICommand_Category = "MyCustomTools"
End Property

Private Property Get ICommand_Checked() As Boolean

End Property

Private Property Get ICommand_Enabled() As Boolean
  ' Add some logic here to specify in what state the application
  ' should be in for the command to be enabled. In this example,
  ' the command is enabled only when there is at least one data
  ' layer loaded in ArcMap.
  Dim pMxDoc As IMxDocument
  Dim pLayerCount As Integer
  'm_pApp is set in OnCreate
  Set pMxDoc =  m_pApp.Document
  pLayerCount =  pMxDoc.FocusMap.LayerCount
  If pLayerCount > 0 Then
    ICommand_Enabled =  True
  Else
    ICommand_Enabled =  False
  End  If
End Property

Private Property Get ICommand_HelpContextID() As Long
  ICommand_HelpContextID =  1234
End Property

Private Property Get ICommand_HelpFile() As String
  ' If the help file is not registered you may need
  ' to  supply the  full path to the file
  ICommand_HelpFile = "MyHelp.hlp"
End Property

Private Property Get ICommand_Message() As String
  'Set the message string that appears in the statusbar of the
  'application when the mouse passes over the command.
  ICommand_Message = "This is my custom command"
End Property

Private Property Get ICommand_Name() As String
  ' Set the internal name of this command. By convention, this
  ' name string contains the category and caption of the command.
  ICommand_Name = "MyCustomTool_MyCommand"
End Property


Private Sub ICommand_OnClick()
  ' Add some code to do some action when the command is clicked. In this
  ' example, a message box is displayed.
  MsgBox "Clicked on my command"
End Sub

Private Sub ICommand_OnCreate(ByVal hook As Object)
  ' The hook argument is a pointer to Application object.
  ' Establish a hook to the application
  Set m_pApp = hook
End Sub


Private Property Get ICommand_Tooltip() As String
  'Set the string that appears in the screen tip.
  ICommand_Tooltip = "MyCommand"

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值