在Visual Basic中实现ICommand接口

文章编号: 391
软件: ArcInfo Desktop 8.3,9.0,ArcEditor 8.3,9.0,ArcView 8.3,9.0
操作系统: N/A
已邀请:

易智瑞技术支持

赞同来自:

在dll中创建自定义的命令和工具,需要实现ICommand接口,下面就是实现Icommand接口的过程描述。
1 创建一个Visual Basic ActiveX DLL工程;
命名类名称为'clsMyCommand'
命名工程名称为'AoDeomo'
2 在常规声明段,输入

Implements ICommand

3 在代码窗口,使用对象下拉列表(左边),选择Icommand;
4 在代码窗口,使用功能下拉列表,选择ICommand的的成员;
5 为Caption属性写实现代码;

Private Property Get ICommand_Caption() As String
ICommand_Caption = "MyCommand"
End Property

6 为Category属性写实现代码;

Private Property Get ICommand_Category() As String
ICommand_Category = "ArcObjects Custom Commands"
End Property

7 为Check属性写实现代码;

Private Property Get ICommand_Checked() As Boolean
ICommand_Checked = False
End Property

注意:false表示处于非恩下状态
8 为Enabled属性写实现代码;

Private Property Get ICommand_Enabled() As Boolean
ICommand_Enabled = True
End Property

注意:当Enabled属性设为真,用户可以能使用这个按钮。
9 为HelpContextID属性写实现代码

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

注意:0表示没有自定义的帮助。
10 为HelpFile属性写实现代码;

Private Property Get ICommand_HelpFile() As Long
ICommand_HelpFile = ""
End Property

注意:使用0长度的字符串表示没有自定义的帮助文件。
11 为Message属性写实现代码

Private Property Get ICommand_Message() As String
ICommand_Message = "MyCommand"
End Property

注意:这个字符串会在arcmap的状态栏中出现。
12 为Name属性写实现代码;

Private Property Get ICommand_Name() As String
ICommand_Name = "MyCommand"
End Property

13 为Tooltip属性写实现代码;

Private Property Get ICommand_Tooltip() As String
ICommand_Tooltip = "Tooltip: MyCommand"
End Property

注意:这个字符串会在鼠标移动到按钮上时提示。
14 在常规申明段,加上下面两句,这是关系到此命令在arcmap中的使用的。

Option Explicit

Private m_pApp As IApplication
Implements ICommand

15 在OnCreate方法中,传递hook到应用程序;

Private Sub ICommand_OnCreate(ByVal hook As Object)
Set m_pApp = hook
End Sub

16 当按钮被点击时执行的代码写在OnClick事件中;

Private Sub ICommand_OnClick()
MsgBox "MyCommand"
m_pApp.Caption = "The OnClick method for MyCommand has executed"
End Sub

17 在代码窗口,在对象下拉列表中选择Class,在功能下拉列表中选择每一个Class的成员;
18 在Class的Terminate方法中,释放application的引用;

Private Sub Class_Terminate()
Set m_pApp = Nothing
End Sub

19 保存工程;
20 编译dll为AoDemo_clsMyCommand.dll;
21 在ArcMap中使用此自定义的dll;
A 打开ArcMap,点击工具菜单,选择自定义。
B 选择命令。
C 单击 "从文件添加"。
D 选择dll文件,并打开。
E 把此工具拖到某一个工具条上,关闭自定义对话框。
22 测试结果;




创建时间:2004-08-13
最近更新:2004-08-13


原文链接
http://support.esrichina.com.cn/2004/0813/391.html

要回复问题请先登录注册