gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:1582回复:3

如何用VB编写一个dll定制arcmap[系列教程]

楼主#
更多 发布于:2005-01-12 02:07
<TABLE width="100%">

<TR>
<TD class=subtitle colSpan=6>
<P>传递ArcMap应用程序对象到VB窗口中</P>
<P>内容摘要</P></TD></TR>
<TR>
<TD class=txt colSpan=6>当你开发一个包含一个窗口的vb ActiveX DLL工程时,你需要传递一个ArcMap应用对象到这个窗口中。</TD></TR>
<TR>
<TD class=subtitle colSpan=6>过程描述</TD></TR>
<TR>
<TD class=txt colSpan=6>1 创建一个新的Visual Basic ActiveX DLL工程,它需要实现ICommand接口。
'创建一个类,命名为clsApp;
'命名工程AoDemo;
2 添加一个Form到工程中,并命名为frmApp.
3 在frmApp代码窗口的常规声明区,声明一个模版级别的IApplication变量,代码如下:
Option Explicit
Private m_pApp As IApplication
4 在frmApp窗口中添加对Application进行Get和Set的操作的属性,代码如下:
Public Property Set Application(ByVal pApp As IApplication)
Set m_pApp = pApp
' *************************
' Add your custom code here
' *************************
End Property

Public Property Get Application() As IApplication
Set Application = m_pApp
End Property
5 在类模版clsApp中,添加Icommand接口的OnCreate方法的实现代码,如下:
Private Sub ICommand_OnCreate(ByVal hook As Object)

Set frmApp.Application = hook

End Sub
6 在clsApp中的Class_Terminate方法中,要记得释放应用程序的引用,代码如下:
Private Sub Class_Terminate()
Set frmApp.Application = Nothing
Unload frmApp
End Sub</TD></TR></TABLE>
[此贴子已经被作者于2005-1-12 2:09:04编辑过]
喜欢0 评分0
GIS麦田守望者,期待与您交流。
kilojin
路人甲
路人甲
  • 注册日期2005-03-10
  • 发帖数22
  • QQ
  • 铜币188枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-03-30 11:54
收下!!<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
Andrew
路人甲
路人甲
  • 注册日期2004-07-28
  • 发帖数37
  • QQ
  • 铜币225枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-03-30 10:30
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2005-01-12 02:08
<P>在Visual Basic中实现ICommand接口</P><P><TABLE width="100%"><TR><TD class=subtitle colSpan=6>内容摘要</TD></TR><TR><TD class=txt colSpan=6>在dll中创建自定义的命令和工具,需要实现ICommand接口,下面就是实现Icommand接口的过程描述。</TD></TR><TR><TD class=subtitle colSpan=6>过程描述</TD></TR><TR><TD class=txt colSpan=6>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 测试结果;</TD></TR></TABLE></P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部