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

提交評論