ArcEngine-开发文档ArcGISAO开发_第1页
ArcEngine-开发文档ArcGISAO开发_第2页
ArcEngine-开发文档ArcGISAO开发_第3页
ArcEngine-开发文档ArcGISAO开发_第4页
ArcEngine-开发文档ArcGISAO开发_第5页
已阅读5页,还剩214页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

-.zArcEngine开发根底篇开发环境如何在ArcMap的VBA环境中编程ArcMap是ArcGIS家族的成员之一,它内置了一种集成编程环境―VBA〔VisaulBasicforApllications〕。通过VBA编程,用户不但可以扩展ArcMap的菜单、工具条等,而且可以完成大多数用户的特定需求。ArcMap中VBA编程的方法有两种,一种是写VBA宏,另一种是创立UIControl并在其事件中写入实现用户需求的代码。下面列出两种方法的一般步骤。方法一:写VBA宏〔直接在VBA编辑器中编辑函数和过程〕1、如图1,单击菜单栏中的<Tools>命令,选择<Macros>的<VisualBasicEditor>项,直接启动ArcMap的VBA编辑器;或者选择<Macros>的<Macros>项,进入如图2所示Macro对话框,在“MacroName〞文本框中输入要创立的宏的名称,并点<Create>按钮,启动VBA编辑器。图1启动Macro对话框/启动VBA编辑器图2Macro对话框2、在图3所示的窗口中,用户可以根据实际选择在Normal节点或者Project节点的ThisDocument、Forms、Modules中编写宏〔函数或过程〕,Normal节点下所写的宏系统自动保存,除非用户删除,否则它将始终存在并在任何工程中都有效;而在Project节点下所写得宏随工程保存〔如不保存工程,则宏也将不被保存〕,并只在工程中有效。图3VBA编辑器〔VBE〕3、运行VBA宏在VBA编辑器中写好VBA代码后,有两种方式运行:第一,点击VBA编辑器工具条中的〔运行〕按钮,可立即运行写好的代码;第二,退出VBA编辑器,重新启动Macro对话框,如图2,选择要运行的VBA宏名称,点击<Run>按钮即可运行相应的VBA宏。方法二:创立UIControl〔交互式VBA编程〕1、用鼠标右击任何工具栏〔条〕,在弹出的上托式菜单中选择<Customize>菜单项,如图4,进入图5所示的Customize对话框。图4启动“Customize〞对话框2、切换到“Customize〞对话框的“mands〞页,选中“UIControls〞后点击<NewUIControl>按钮,进入图6所示的“NewUIControl〞对话框。3、在“NewUIControl〞对话框中,用户可根据需要选择UIControl类型:UIButtonControl:创立Button;UIToolControl:创立与Map交互的Tool;UIEditBo*Control:创立EditBo*;UIboBo*Control:创立boBo*。最后点击<Create>按钮只创立UIControl或者点击<CreateandEdit>按钮创立UIControl并进入VBA编辑器。与方法一不同,此时应在UIControl的事件中进展VBA编程。图5Customize对话框图6NewUIControl对话框4、UIControl创立后,在图5所示的“Customize〞对话框选中UIControl并将其拖置到任意工具条上,用户便可象使用系统已有的Control一样使用所创立的UIControl。如何在VB环境中利用ArcObjects组件开发Active*DLL节讨论了如何在ArcGis的VBA环境中编程,虽然通过这种方式可以完成大多数用户的定制需求,但是,在*些情况下,对于特殊的应用,用户需要脱离ArcGIS环境而在VB开发环境中开发外部独立的应用程序,这种外部独立的应用程序有两种形式:Active*DLL和StandardE*E。StandardE*E的开发将在1.1.4中讨论,本节将讨论Active*DLL的开发,其关键是引用ArcObjects对象库和实现ArcObjects接口〔例如Imand,ITool,IToolBar等〕。下面介绍在VB环境利用ArcObjects组件开发Active*DLL的一般步骤。1、启动VB开发环境,在图7所示的“NewProject〞对话框中选择“Active*DLL〞项,并点击<翻开>按钮,进入VBE环境。图7NewProject对话框2、引用ArcObjects对象库:首先点击<Project>菜单中的<References>项,如图8,进入对象库引用对话框,如图9。图8启动对象库引用对话框图9对象库引用对话框3、对象库引用对话框〔图9〕中选中“EsriArcMapObjectLibrary〞和“EsriObjectLibrary〞两项,并点击<OK>按钮,返回VBE环境。4、一般在类模块中写入实现特定ArcObjects接口的代码,如图10,然后运行<File>菜单中的<Makeproject1.dll>项,生成DLL文件,如图11。〔project1.dll随工程名改变〕。图10类模块编辑窗口图11生成DLL文件如何在ArcMap中加载利用ArcObjects组件开发的Active*DLL用户通过中介绍的方法开发好一个Active*DLL程序后,便可根据实际需要,在ArcMap环境下加载这个Active*DLL程序。其一般步骤如下:1、用鼠标右击任何工具栏〔条〕,点击弹出的上托式菜单中的<Customize>菜单项〔参见图4〕。2、在Customize对话框中,根据被加载DLL的类型切换到“Toolbars〞或者“mands〞页〔参见图5〕,然后点击<AddFromFile>按钮。3、在“翻开文件〞对话框中〔Windows通用“翻开文件〞对话框,图略〕,选择被加载的Dll文件,并点击<翻开>按钮。4、如果加载是“mands〞,则在图5所示的对话框中显示加载的mand,并可以将其拖置于任何工具条上;如果加载是“ToolBars〞,则在图12所示的对话框中显示加载的ToolBar,选中后即可在ArcMap中显示。图12加载ToolBar如何在VB环境中利用ArcObjects控件开发E*E利用ArcObjects控件开发E*E的前三步类似于中开发“AcrtiveDll〞的前三步,唯一不同的是在“NewProject〞对话框中选择“StandardE*E〞。4、点击<Project>菜单项中的<ponents>项,翻开“ponents〞对话框,如图13。图13翻开ponents对话框5、在“ponents〞对话框中,切换到Controls页,并选中“ESRIMapControl〞项,点击<应用>或<确定>按钮,如图14。图14ponents对话框6、如图15所示,加载MapControl控件之后,在VBE的控件面板中出现了MapControl控件图标,用户便可以象在Form中添加Button一样在Form中添加MapControl控件,并利用它开发E*E。图15添加MapControl控件用户界面如何创立定制的按钮(Button)本例要实现的是如何创立定制的按钮(Button)。要点用户通过在类模块中实现Imand接口来创立定制的按钮〔mand〕。Imand接口包括caption、name、category、bitmap、message〔StatusBarr的提示信息〕、tooltip〔微帮助〕、helpconte*tid、helpfile、enabled以及checked等十个属性和OnCreate、OnClick两个事件。从Imand接口的OnCreate事件中获取的ArcMap的Application实例必须用一个公共变量保存,以便在其它事件中(或者其它接口的事件中甚至整个工程中)使用。·OnCreate事件的参数hook传入的是一个Object,也就是ArcMAP的Application实例,可把它赋给一个IApplication接口的变量,便获得了ArcMAP的实例。·在OnClick事件中写入相关代码,表示按下按钮时要实现的功能.程序说明程序在类模块中实现Imand接口来创立自己的按钮(Button)代码OptionE*plicit'实现Imand接口ImplementsImandDimm_pPictureasPictureDimm_pApplicationAsIApplicationPrivateSubClass_Initialize()'调入.RES文件中ID为101的BitMap作为该按钮的显示图片Setm_pPicture=LoadResPicture(101,vbResBitmap)EndSubPrivatePropertyGetImand_Bitmap()AsesriCore.OLE_HANDLEImand_Bitmap=m_pPictureEndPropertyPrivatePropertyGetImand_Caption()AsStringImand_Caption="CreateButton"EndPropertyPrivatePropertyGetImand_Category()AsStringImand_Category="CreateButton"EndPropertyPrivatePropertyGetImand_Checked()AsBooleanEndPropertyPrivatePropertyGetImand_Enabled()AsBooleanImand_Enabled=TrueEndPropertyPrivatePropertyGetImand_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetImand_HelpFile()AsStringEndPropertyPrivatePropertyGetImand_Message()AsStringEndPropertyPrivatePropertyGetImand_Name()AsStringImand_Name="CreateButton"EndPropertyPrivateSubImand_OnClick()'参加按下按钮时实现的功能代码。在这里,'按钮按下时显示ArcMap的Document的TittleDimpDocumentAsIDocumentSetpDocument=m_pApplication.DocumentMsgBo*pDocument.TitleEndSubPrivateSubImand_OnCreate(ByValhookAsObject)'获取ArcMap的Application实例Setm_pApplication=hookEndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="CreateButton"EndProperty如何创立定制的Tool本例要实现的是如何创立定制的Tool要点用户在类模块中实现Imand〔参见〕和ITool接口。ITool接口包括mousemove,mousebuttonpress/release,keyboardkeypress/release,double-click以及rightclick等事件、Cursor属性和Refresh方法。Tool既具有Button的功能,又具有与ArcMAP界面交互的功能,Button的功能代码必须写在Imand的OnClick事件中,而所有实现交互功能的代码必须写在Itool接口的各个事件中。Itool接口的各个事件,用户可以在其中写入相关代码,表示用户与ArcMAP界面交互时一旦触发*事件要实现的功能。程序说明程序在类模块中实现Imand和Itool接口来创立自己的Tool.代码OptionE*plicit'实现Imand和Itool接口ImplementsImandImplementsIToolDimm_pApplicationAsIApplicationDimm_pBitmapAsIPictureDispDimm_pCursorAsIpictureDispPrivateSubClass_Initialize()Setm_pBitmap=LoadResPicture(101,0)'从.RES文件中调入ID为102的图片作为按下Tool后的MouseCursorSetm_pCursor=LoadResPicture(102,2)EndSubPrivatePropertyGetImand_Bitmap()AsesriCore.OLE_HANDLEImand_Bitmap=m_pBitmapEndPropertyPrivatePropertyGetImand_Caption()AsStringImand_Caption="MyTool"EndPropertyPrivatePropertyGetImand_Category()AsStringImand_Category="MyCustomTools"EndPropertyPrivatePropertyGetImand_Checked()AsBooleanEndPropertyPrivatePropertyGetImand_Enabled()AsBooleanImand_Enabled=TrueEndPropertyPrivatePropertyGetImand_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetImand_HelpFile()AsStringEndPropertyPrivatePropertyGetImand_Message()AsStringImand_Message="Thisismycustomtool"EndPropertyPrivatePropertyGetImand_Name()AsStringImand_Name="MyCustomTool_MyTool"EndPropertyPrivateSubImand_OnClick()'参加按下按钮时实现的功能代码MsgBo*"Clickedonmymand"EndSubPrivateSubImand_OnCreate(ByValhookAsObject)'获取ArcMAP的Application实例Setm_pApplication=hookEndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="MyTool"EndPropertyPrivatePropertyGetITool_Cursor()AsesriCore.OLE_HANDLEITool_Cursor=m_pCursorEndPropertyPrivateFunctionITool_Deactivate()AsBoolean'如果ITool_Deactivate设为False,则Tool不可用ITool_Deactivate=TrueEndFunctionPrivateFunctionITool_OnConte*tMenu(ByVal*AsLong,ByValYAsLong)AsBoolean'在这里可以参加用户代码,点击Mouse右键时显示一个定制的conte*tmenuEndFunctionPrivateSubITool_OnDblClick()'在这里参加Mouse双击时的功能代码EndSubPrivateSubITool_OnKeyDown(ByValkeyCodeAsLong,ByValShiftAsLong)EndSubPrivateSubITool_OnKeyUp(ByValkeyCodeAsLong,ByValShiftAsLong)EndSubPrivateSubITool_OnMouseDown(ByValButtonAsLong,ByValShiftAsLong,_ByVal*AsLong,ByValYAsLong)'参加Mouse单击时的功能代码IfButton=1ThenDimpPointAsIPointDimpM*ApplicationAsIM*ApplicationSetpM*Application=m_pAppSetpPoint=pM*Application.Display.DisplayTransformation.ToMapPoint(*,Y)m_pApplication.StatusBar.Message(0)=Str(pPoint.*)&","&Str(pPoint.Y)EndIfEndSubPrivateSubITool_OnMouseMove(ByValButtonAsLong,ByValShiftAsLong,_ByVal*AsLong,ByValYAsLong)'参加Mouse移动时的功能代码m_pApplication.StatusBar.Message(0)="ITool_OnMouseMove"EndSubPrivateSubITool_OnMouseUp(ByValButtonAsLong,ByValShiftAsLong,_ByVal*AsLong,ByValYAsLong)'参加释放Mouse时的功能代码m_pApplication.StatusBar.Message(0)="ITool_OnMouseUp"EndSubPrivateSubITool_Refresh(ByValhDCAsesriCore.OLE_HANDLE)EndSub如何创立定制的工具条(ToolBar)本例要实现的是如何创立定制的工具条(ToolBar)。就必须在类模块中实现IToolBarDef接口。IToolBarDef接口包括Caption、ItemCount及Name三个属性和GetItemInfo方法。要点通过在类模块中实现IToolBarDef接口。IToolBarDef接口包括Caption、ItemCount及Name三个属性和GetItemInfo方法。·ItemCount属性表示ToolBar显示的条目(Button、Tool或其它控件)数。·GetItemInfo方法定义工具条上各条目的CLSID,其中,参数pos表示条目在ToolBar中的位置,itemDef是定义相应位置的条目的IItemDef对象。·工具条条目的CLSID分为两种:1、系统CLSID,代表ArcGIS的一个功能,其引用方式为"esriCore.命令名称",如"esriCore.AddDatamand"、"esriCore.FileSavemand"等。2、用户定制CLSID,表示用户自己定义的功能。其引用方式为"工程名称.定制功能类名称",如"ToolBarDef.ClsBar"。必须注意,这里“定制功能类名称〞是工程中实现的一个功能类名称,“工程名称〞即为当前工程的名称〔不是DLL文件名,也不是工具条的名称〕,每次新建一个工程时,系统默认的工程名在*些情况下无法使用〔在中文版的VB中是一个乱字符〕,必须改名前方能用。程序说明程序在类模块中实现IToolBarDef接口来创立自己的工具条(ToolBar)。代码OptionE*plicitImplementsIToolBarDefPrivatePropertyGetIToolBarDef_Caption()AsStringIToolBarDef_Caption="CustomToolBar"EndPropertyPrivateSubIToolBarDef_GetItemInfo(ByValposAsLong,ByValitemDefAs_esriCore.IItemDef)'这里假设在当前工程(工程名称为ToolBarDef)中定义了一个类模块(名为ClsBar),'它实现了Imand接口(可参照)SelectCaseposCase0'用户自定义条目itemDef.ID="ToolBarDef.ClsBar"itemDef.Group=FalseCase1'系统条目itemDef.ID="esriCore.AddDatamand"itemDef.Group=FalseEndSelectEndSubPrivatePropertyGetIToolBarDef_ItemCount()AsLongIToolBarDef_ItemCount=2EndPropertyPrivatePropertyGetIToolBarDef_Name()AsStringIToolBarDef_Name="CustomToolBar"EndProperty如何创立定制的MultiItem本例要实现的是如何创立定制的MultiItem。要点需要实现IMultiItem接口,但不需要同时实现Imand接口。IMultiItem接口包括Caption,itemCaption,ItemBitmap,ItemEnabled,ItemChecked,Message及Name等属性和OnItemClick,OnPopup事件。·itemCaption,ItemBitmap,ItemEnabled,ItemChecked等属性的参数inde*表示当前Item的下标索引。·OnPopup事件的参数hook同Imand接口的OnCreate事件的参数hook一样,传入ArcGIS的Application实例,同时,该事件返回将要显示的Item数目。·OnItemClick事件的参数Inde*表示用户当前点击的Item的索引,用户根据该索引分别定义点击各个Item时实现的功能。程序说明程序在类模块中实现IMultiItem接口来创立定制自己的MultiItem。代码OptionE*plicitImplementsIMultiItemPrivatem_pAppAsIApplication'ArcMap的DocumentPrivatem_pM*DocAsIM*Document'当前FocusMapPrivatem_pMapAsIMap'Map中的层数Privatem_pLayertAsLongPrivatePropertyGetIMultiItem_Caption()AsStringIMultiItem_Caption="ZoomToLayers"EndPropertyPrivatePropertyGetIMultiItem_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetIMultiItem_HelpFile()AsStringEndPropertyPrivatePropertyGetIMultiItem_ItemBitmap(ByValInde*AsLong)AsesriCore.OLE_HANDLEEndPropertyPrivatePropertyGetIMultiItem_ItemCaption(ByValInde*AsLong)AsStringDimiAsInteger'遍历每一个层Fori=0Tom_pLayert-1'如果层号与当前Item的Inde*一样,就设置该Item的CaptionIfInde*=iThenIMultiItem_ItemCaption="Zoomto"&m_pMap.Layer(i).NameEndIfNe*tEndPropertyPrivatePropertyGetIMultiItem_ItemChecked(ByValInde*AsLong)AsBooleanEndPropertyPrivatePropertyGetIMultiItem_ItemEnabled(ByValInde*AsLong)AsBooleanDimiAsInteger'遍历每一个层Fori=0Tom_pLayert-1'如果层号与当前Item的Inde*一样,则当前Item的Enable根据该层的Visible设置。IfInde*=iThenIfm_pMap.Layer(i).VisibleThenIMultiItem_ItemEnabled=TrueEndIfEndIfNe*tEndPropertyPrivatePropertyGetIMultiItem_Message()AsStringIMultiItem_Message="Zoomstothelayer."EndPropertyPrivatePropertyGetIMultiItem_Name()AsStringIMultiItem_Name="ZoomMulti"EndPropertyPrivateSubIMultiItem_OnItemClick(ByValInde*AsLong)DimiAsIntegerDimpEnvAsIEnvelopeDimm_BookMarkAsIAOIBookmark'遍历每一个层Fori=0Tom_pLayert–1'如果层号与当前Item的Inde*一样,则以该层的AreaOfInterest为*围执行ZoomIfInde*=iThenSetpEnv=m_pMap.Layer(i).AreaOfInterestSetm_BookMark=NewAOIBookmarkSetm_BookMark.Location=pEnvm_BookMark.ZoomTom_pMapEndIfNe*tEndSubPrivateFunctionIMultiItem_OnPopup(ByValhookAsObject)AsLongSetm_pApp=hook'获取Map中的层数Setm_pM*Doc=m_pApp.DocumentSetm_pMap=m_pM*Doc.FocusMapm_pLayert=m_pMap.LayerCount'显示的Item数等于层数IMultiItem_OnPopup=m_pLayertEndFunction如何创立定制的菜单(Menu)本例要实现的是如何创立定制的菜单(Menu)。要点用户通过在类模块中实现IMenuDef接口来创立定制的菜单(Menu),如果要使菜单出现在CustomizeDialog的Menus类型中,必须同时实现IrootLevelMenu接口,它说明菜单为rootmenu。IMenuDef接口包括Caption、ItemCount及Name三个属性和GetItemInfo方法。类似IToolBarDef(参照)程序说明程序在类模块中实现IMenuDef接口来创立定制的菜单(Menu)。代码OptionE*plicit'ImplementtheIMenuDefinterfaceandIRootLevelMenuinterfaceImplementsIMenuDefImplementsIRootLevelMenuPrivatePropertyGetIMenuDef_Caption()AsString'Setthestringthatappearsasthemenu'stitleIMenuDef_Caption="MyMenu"EndPropertyPrivateSubIMenuDef_GetItemInfo(ByValposAsLong,_ByValitemDefAsesriCore.IItemDef)'Definethemandsthatwillbeonthemenu.Thebuilt-inArcMap'FullE*tentmand,andFi*edZoomInmandareaddedtothiscustommenu.'IDistheClassIDofthemand.Groupdetermineswhetherthemand'beginsanewgrouponthemenuSelectCaseposCase0itemDef.ID="promenu.clsmultitem"itemDef.Group=FalseCase1itemDef.ID="esriCore.FullE*tentmand"itemDef.Group=TrueCase2itemDef.ID="esriCore.ZoomInFi*edmand"itemDef.Group=FalseEndSelectEndSubPrivatePropertyGetIMenuDef_ItemCount()AsLong'SethowmanymandswillbeonthemenuIMenuDef_ItemCount=3EndPropertyPrivatePropertyGetIMenuDef_Name()AsString'Settheinternalnameofthemenu.IMenuDef_Name="MyMenu"EndProperty如何创立定制的ToolControl本例要实现的是如何创立定制的ToolControl。ToolControl是指具有boBo*的下拉列表或EditBo*的编辑功能的一类控件。要创立定制的ToolControl,必须在类模块中实现Imand和IToolControl接口。IToolControl接口包括hWnd属性和OnDrop,OnFocus事件。要点·IToolControl接口的hWnd属性,承受一个WindowHandle。·IToolControl接口的OnDrop事件,支持ToolControl的拖放,传入参数barType表示Bar类型。·IToolControl接口的OnFocus事件,传入IpletionNotify类型的参数plete,可以通过执行IpletionNotify接口的Setplete方法告之ArcMAP,ToolControl可以失去Focus。程序说明本例中涉及三个模块,详细描述如下,其中,在类模块中实现了IToolBarDef接口来创立自己的ToolControl。代码'1、frmImagebo.frm模块,定义选中bo**一项之后实现的功能。要求在Form上放置一个'Imageb控件〔名为Imagebo1〕和一个ImageList控件〔名为ImageList1〕,并在ImageList1'中添加三*图片。PrivateSubForm_Load()'设置Imagebo1的选择ItemMe.Imagebo1.ImageList=Me.ImageList1Me.Imagebo1.boItems.Add1,"Red","Red"Me.Imagebo1.boItems.Add2,"Blue","Blue"Me.Imagebo1.boItems.Add3,"Green","Green"Me.Imagebo1.boItems(1).Image=1Me.Imagebo1.boItems(2).Image=2Me.Imagebo1.boItems(3).Image=3EndSubPrivateSubImagebo1_Click()'选择颜色DimselAsVariantDimcolorAsVariantSelectCaseselCase"Blue"color=vbBlueCase"Red"color=vbRedCase"Green"color=vbGreenEndSelectDimpDocumentAsIM*DocumentSetpDocument=g_pApplication.Document'设置颜色DimpRgbColorAsIrgbColorSetpRgbColor=NewRgbColorpRgbColor.RGB=color'改变选中局部的颜色DimpSelectionEnvironmentAsISelectionEnvironmentSetpSelectionEnvironment=NewSelectionEnvironmentSetpSelectionEnvironment.DefaultColor=pRgbColor'刷新视图'通知ArcMap,ToolControl现在可以失去Focusg_ppletionNotify.SetpleteEndSub'2、modPublicVars.bas模块,定义工程中用到的全局变量。OptionE*plicitPublicg_pApplicationAsIApplicationPublicg_ppletionNotifyAsIpletionNotify'3、CustImagebo.cls模块,实现接口Imand和IToolControl。OptionE*plicitImplementsImandImplementsIToolControlPrivatePropertyGetImand_Bitmap()AsesriCore.OLE_HANDLEEndPropertyPrivatePropertyGetImand_Caption()AsStringImand_Caption="CustomImagebo"EndPropertyPrivatePropertyGetImand_Category()AsStringImand_Category="DeveloperSamples"EndPropertyPrivatePropertyGetImand_Checked()AsBooleanEndPropertyPrivatePropertyGetImand_Enabled()AsBooleanImand_Enabled=TrueEndPropertyPrivatePropertyGetImand_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetImand_HelpFile()AsStringEndPropertyPrivatePropertyGetImand_Message()AsStringImand_Message="Changefeatureselectioncolor"EndPropertyPrivatePropertyGetImand_Name()AsStringImand_Name="DevelperSamples_CustomImagebo"EndPropertyPrivateSubImand_OnClick()EndSubPrivateSubImand_OnCreate(ByValhookAsObject)Setg_pApp=hookEndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="ChangeSelectionColor"EndPropertyPrivatePropertyGetIToolControl_hWnd()AsesriCore.OLE_HANDLE'将frmImagebo.Imagebo1的WindowHandle赋给IToolControl_hWndEndPropertyPrivateFunctionIToolControl_OnDrop(ByValbarTypeAsesriCore.esriCmdBarType)AsBoolean'仅能将ToolControl拖放到ToolBar上IfbarType=esriCmdBarTypeToolbarThenIToolControl_OnDrop=TrueEndIfEndFunctionPrivateSubIToolControl_OnFocus(ByValpleteAsesriCore.IpletionNotify)Setg_ppletionNotify=pleteEndSub如何创立定、使用制的可停靠窗口(DockableWindow)本例要实现的是如何创立定制的可停靠窗口(DockableWindow)要点用户通过在类模块中实现IDockableWindowDef接口来创立定制的可停靠窗口(DockableWindow)。IDockableWindowDef接口包括Caption、ChildHWND,UserData及Name等属性和OnCreate、OnDestroy事件。·ChildHWND属性表示可停靠窗口包含的Window的Handle。·OnCreate事件的参数hook传入ArcGIS的Application实例。·创立并注册可停靠窗口的步骤:1、实现IdockableWindowDef接口(参见实例);2、编译成DLL;3、调用windows目录下system32子目录下的regsvr32.e*e用下面的形式注册编译好的DLL:win目录\system32\regsvr32.e*e<路径>\<文件名>.dll4、运行<arcmap目录>\arce*e81\Bin\categories.e*e,在翻开的ponentCatregoryManager中找到ESRIM*DockableWindow,点击AddObject…按钮将上面注册的DLL文件参加,并选中实现IdockableWindowDef接口的类名即可。程序说明类模块ClsDockableWindow只是创立与注册可停靠窗口,但还不能用,还必须定义一个IdockableWindow接口的变量引用注册的类〔必须用IdockableWindowsManager接口的GetDockableWindow获取,其ID号用"实现IdockableWindowDef接口的工程名project1.实现IdockableWindowDef接口的类名class1"〕。代码'类模块ClsDockableWindowOptionE*plicitImplementsIDockableWindowDefDimm_pApplicationAsIApplicationPrivatePropertyGetIDockableWindowDef_Caption()AsStringIDockableWindowDef_Caption="DockableWindow"EndPropertyPrivatePropertyGetIDockableWindowDef_ChildHWND()AsesriCore.OLE_HANDLE'将FrmDWin窗口的Handle赋给IDockableWindowDef_ChildHWNDIDockableWindowDef_ChildHWND=FrmDWin.hWndEndPropertyPrivatePropertyGetIDockableWindowDef_Name()AsStringIDockableWindowDef_Name="docwin"EndPropertyPrivateSubIDockableWindowDef_OnCreate(ByValhookAsObject)Setm_pApplication=hookEndSubPrivateSubIDockableWindowDef_OnDestroy()Setm_pApplication=NothingEndSubPrivatePropertyGetIDockableWindowDef_UserData()AsVariantEndProperty'类模块class1OptionE*plicitImplementsImandDimm_pAppAsIApplicationDimm_pDWMgrAsIDockableWindowManagerDimm_pDWinAsIDockableWindowPrivatePropertyGetImand_Bitmap()AsesriCore.OLE_HANDLEEndPropertyPrivatePropertyGetImand_Caption()AsStringImand_Caption="DockableWindow"EndPropertyPrivatePropertyGetImand_Category()AsStringImand_Category="DockableWindow"EndPropertyPrivatePropertyGetImand_Checked()AsBooleanEndPropertyPrivatePropertyGetImand_Enabled()AsBooleanImand_Enabled=TrueEndPropertyPrivatePropertyGetImand_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetImand_HelpFile()AsStringEndPropertyPrivatePropertyGetImand_Message()AsStringEndPropertyPrivatePropertyGetImand_Name()AsStringImand_Name="DocWin"EndPropertyPrivateSubImand_OnClick()m_pDWin.ShowNotm_pDWin.IsVisibleEndSubPrivateSubImand_OnCreate(ByValhookAsObject)Setm_pApp=hook'QI(DockableWindow)Setm_pDWMgr=hookDimpidAsNewUIDpid.Value="Prodockablewindow.Clsdockablewindow"Setm_pDWin=m_pDWMgr.GetDockableWindow(pid)EndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="DockableWindow"EndProperty如何创立、使用定制的E*tension本例要实现的是如何创立、使用定制的E*tension。要点用户需要实现IE*tension接口来创立定制的E*tension。IE*tension接口包括Name属性和startup和shutdown事件。·创立并注册E*tension的步骤:1.实现IE*tension接口;2.编译成DLL;3.调用windows目录下system32子目录下的regsvr32.e*e用下面的形式注册编译好的DLLwin目录\system32\regsvr32.e*e<路径>\<文件名>.dll4.运行<arcmap目录>\arce*e81\Bin\categories.e*e,在翻开的ponentCatregoryManager中找到ESRIM*E*tensions,点击AddObject…按钮将上面注册的DLL文件参加,并选中实现IE*tension接口的类名即可。程序说明用户通过在类模块中实现IE*tension接口来创立定制的E*tension。E*tension将在ArcMap翻开时自动加载,在ArcMap关闭时自动卸载。代码OptionE*plicitImplementsIE*tensionDimm_pApplicationAsIApplication'NeedtolistenfortheM*DocumenteventsDimWithEventsm_pDocumentAsM*DocumentPrivatePropertyGetIE*tension_Name()AsStringIE*tension_Name="MyE*tension"EndPropertyPrivateSubIE*tension_Shutdown()'ClearthereferencetotheApplicationandM*DocumentSetm_pApplication=NothingSetm_pDocument=NothingEndSubPrivateSubIE*tension_Startup(initializationDataAsVariant)'Thise*tensionisanArcMapE*tension.Whenthise*tensioninloadedon'ArcMapstartup,initializationDataispassedinasareferencetothe'ApplicationobjectSetm_pApplication=initializationData'StartlisteningfortheM*Documentevents.Setm_pDocument=m_pApp.DocumentEndSubPrivateFunctionm_pDocument_NewDocument()AsBoolean'DosomethingwhenanewdocumentiscreatedMsgBo*"Creatinganewdocument."EndFunctionPrivateFunctionm_pDocument_OpenDocument()AsBoolean'Sosomethingwhenadocumentisopened.MsgBo*"Openingadocument"EndFunction如何使用状态条(StatusBar)与进度条(ProgressBar)本例要演示的是如何使用状态条(StatusBar)与进度条(ProgressBar)。实现后的结果为在ArcMap中,状态条位于其底部,它显示ArcMAP当前状态的信息,包含进度条。要点一般情况下,通过ArcMAP的Application实例获取IstatusBar的实例,然后再通过StatusBar获取IprogressBar的实例,并将IprogressBar的实例赋给IstepProgressor类型的变量。程序说明运行函数ShowProgress将在ArcMap的下方添加一个状态条(StatusBar)和进度条(ProgressBar)。代码SubShowProgress()OnErrorGoToerr1DimpDocumentAsIM*DocumentDimpMapAsIMapDimpLayerAsILayerDimpFeatureLayerAsIFeatureLayerDimpFeatureCursorAsIFeatureCursorDimpFeatureClassAsIFeatureClassDimpFeatureAsIFeatureDimdSumAsDoubleDimlFieldInde*AsLongDimlNumFeatAsLongDimdIntervalAsDoubleSetpDocument=Application.DocumentSetpMap=pDocument.FocusMapSetpLayer=pMap.Layer(0)SetpFeatureLayer=pLayerSetpFeatureClass=pFeatureLayer.FeatureClassSetpFeatureCursor=pFeatureLayer.Search(Nothing,True)DimpStatusBarAsIStatusBarSetpStatusBar=Application.StatusBarDimpStepProgressorAsIStepProgressorSetpStepProgressor=pStatusBar.ProgressBarlNumFeat=pFeatureClass.FeatureCount(Nothing)dInterval=lNumFeat/100SetpFeature=pFeatureCursor.Ne*tFeature'字段名"FID"用户根据实际而改变lFieldInde*=pFeature.Fields.FindField("FID")DimPauseTime,Start,Finish,TotalTime,iPauseTime=0.5pStepProgressor.MinRange=1pStepProgressor.Ma*Range=lNumFeatpStepProgressor.StepValue=dIntervalFori=1TolNumFeatdSum=dSum+pFeature.Value(lFieldInde*)SetpFeature=NothingSetpFeature=pFeatureCursor.Ne*tFeaturepStepProgressor.Position=ipStepProgressor.Message="Readingrecord"&Str(i)&".Sum="&Str(dSum)pStepProgressor.SteppStepProgressor.ShowStart=TimerDoWhileTimer<Start+PauseTimeDoEventsLoopNe*tpStepProgressor.HideE*itSuberr1:MsgBo*Err.DescriptionEndSub如何使用ArcGIS的对话框添加对话框可以通过相应的接口实现。比方“添加数据对话框〞使用IaddDataDialog接口,“生成点坐标对话框〞使用ICoordinateDialog接口,“生成字符串对话框〞使用IGetStringDialog接口,“生成数值对话框〞使用INumberDialog接口等等。本例以添加数据对话框(AddDataDialog)为例,讲述对话框是如何通过接口实现添加的。要点用户通过实现IaddDataDialog接口来创立定制的添加数据对话框,IaddDataDialog接口包括Document和Map属性和Show事件。程序说明在程序中除了必须生成IaddDataDialog接口的实例外,还必须指定对话框的Document和Map。当为AddDataDialog指定Document和Map之后,系统会自动将用户选择的数据参加到指定Document和Map中。最后实现在ArcMap中添加数据的对话框。代码SubShowProgress()DimmDocumentAsIM*DocumentDimmAddDataDialogAsIAddDataDialogSetmAddDataDialog=NewAddDataDialogSetmDocument=ThisDocumentmAddDataDialog.Document=mDocumentmAddDataDialog.Map=mDocument.FocusMapmAddDataDialog.ShowApplication.hWnd,TrueEndSub如何调用ArcMap中现有的功能如何调用ArcMap中现有的功能,比方菜单栏、工具栏中的*些功能。这些都可以通过UID来实现。本例是通过UID调用“另存为〞功能。可以通过两种方法得到UID:方法一:运用ArcID模块要点通过ArcID获得UID,ArcID是ArcMap的VBA中的模块。只需要知道要调用功能的名称运用代码就可以实现。程序说明程序通过运用ArcID模块和命令名称来实现调用“另存为〞的功能。代码SubE*ecuteCmd()DimpmandItemAsImandItem'UseArcIDmoduleandtheNameoftheSaveAsmandSetpmandItem=Application.Document.mandBars.Find(arcid.File_SaveAs)pmandItem.E*ecuteEndSub方法二:直接写代码要点通过直接写代码获得UID实现调用功能。程序说明写入文件菜单项的GUID(CLSID或ProgID)来调用文件菜单项,同时还需要通过设置Subtype的值来调用文件菜单项的“另存为〞功能。代码SubE*ecuteCmd2()DimpUIDAsNewUIDDimpmandItemAsImandItem'UsetheGUIDoftheSavemandpUID.Value="{119591DB-0255-11D2-8D20-080009EE4E51}"'oryoucanusetheProgID'pUID.Value="esriCore.M*FileMenuItem"pUID.SubType=3SetpmandItem=Application.Document.mandBars.Find(pUID)pmandItem.E*ecuteEndSub如何创立放大镜(虫眼)本例要实现的是如何创立放大镜(虫眼),将所选区域放大一定的倍数。要点用户通过定义IMapInset、IMapInsetWindow、IDataWindowFactory三个接口,运用它们的方法、属性来创立放大镜(虫眼)。程序说明运用这个子程序生成了一个新的放大镜窗口,在本例中将放大率设定为200%代替原来的400%。代码PublicSubCreateMagnifierWindow()DimpMapInsetAsIMapInsetDimpMapInsetWindowAsIMapInsetWindowDimpDataWindowFactoryAsIDataWindowFactorySetpDataWindowFactory=NewMapInsetWindowFactoryIfpDataWindowFactory.CanCreate(Application)ThenSetpMapInsetWindow=pDataWindowFactory.Create(Application)SetpMapInset=pMapInsetWindow.MapInset'Setthezoompercentto200%pMapInset.ZoomPercent=200pMapInsetWindow.ShowTrueEndIfEndSubGeoDataBase如何加载Shape文件本例实现的是在ArcMap中连接指定的Shape文件,并将其加载到当前激活的Map中。要点通过FeatureLayer类实现IFeatureLayer接口对象,设置IFeatureLayer.FeatureClass属性和Name属性,使用IMap.AddLayer方法将新层添加到当前地图。利用IWorkspaceFacktory接口、IFeatureWorkspace接口和IFeatureLayer接口实现连接Shape文件程序说明函数OpenShapeFile根据输入的Shape文件路径sFilePath,将文件名为sFileName的Shape文件连接到当前激活的Map中去。代码PrivateSubOpenShapeFile(ByValsFilePathAsString,ByValsFileNameAsString)DimpWorkspaceFactoryAsIWorkspaceFactoryDimpFeatureWorkspaceAsIFeatureWorkspaceDimpFeatureLayerAsIFeatureLayerDimpM*DocumentAsIM*DocumentDimpMapAsIMapDimsDirAsStringOnErrorGoToErrorHandler:sDir=Dir(sFilePath&"\"&sFileName&".shp")If(sDir=")ThensDir=Dir(sFilePath&"\"&sFileName)If(sDir=")ThenMsgBo*("文件不存在")E*itSubEndIfEndIf'CreateanewShapefileWorkspaceFactoryobjectandopenashapefilefolderSetpWorkspaceFactory=NewShapefileWorkspaceFactorySetpFeatureWorkspace=pWorkspaceFactory.OpenFromFile(sFilePath,0)'CreateanewFeatureLayerandassignashapefiletoitSetpFeatureLayer=NewFeatureLayerSetpFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass(sFileName)'AddtheFeatureLayertothefocusmapSetpM*Document=Application.DocumentSetpMap=pM*Document.FocusMappMap.AddLayerpFeatureLayerE*itSubErrorHandler:MsgBo*Err.DescriptionEndSubPrivateSubUIButtonControl1_Click()DimpVBProjectAsVBProjectOnErrorGoToErrorHandler:SetpVBProject=ThisDocument.VBProjectOpenShapeFilepVBProject.FileName&"\..\..\..\.."&"\data\","Continents"E*itSubErrorHandler:MsgBo*Err.DescriptionEndSub如何在ArcMap中参加Te*t和dBASE文件本例实现的是如何在当前的ArcMap中参加Te*t文件和dBASE文件。要点首先为Te*t文件或dBASE文件创立一个与之对应的ITable接口对象,然后通过IMap实例获得IStandaloneTable接口对象和IStandaloneTableCollection接口对象,并设置其属性,最后使用IStandaloneTableCollection.AddStandaloneTable方法将Te*t文件或dBASE文件参加到当前的ArcMap中。参加Te*t文件或dBASE文件的区别仅在于创立ITable对象时IWorkspaceFactory的类型不同,参加Te*t文件时是Te*tFileWorkspaceFactory类型,参加dBASE文件时是ShapefileWorkspaceFacto

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论