使用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"