ArcEngine-開發(fā)文檔ArcGISAO開發(fā)_第1頁
ArcEngine-開發(fā)文檔ArcGISAO開發(fā)_第2頁
ArcEngine-開發(fā)文檔ArcGISAO開發(fā)_第3頁
ArcEngine-開發(fā)文檔ArcGISAO開發(fā)_第4頁
ArcEngine-開發(fā)文檔ArcGISAO開發(fā)_第5頁
已閱讀5頁,還剩214頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

-.zArcEngine開發(fā)根底篇開發(fā)環(huán)境如何在ArcMap的VBA環(huán)境中編程ArcMap是ArcGIS家族的成員之一,它內(nèi)置了一種集成編程環(huán)境―VBA〔VisaulBasicforApllications〕。通過VBA編程,用戶不但可以擴(kuò)展ArcMap的菜單、工具條等,而且可以完成大多數(shù)用戶的特定需求。ArcMap中VBA編程的方法有兩種,一種是寫VBA宏,另一種是創(chuàng)立UIControl并在其事件中寫入實(shí)現(xiàn)用戶需求的代碼。下面列出兩種方法的一般步驟。方法一:寫VBA宏〔直接在VBA編輯器中編輯函數(shù)和過程〕1、如圖1,單擊菜單欄中的<Tools>命令,選擇<Macros>的<VisualBasicEditor>項(xiàng),直接啟動(dòng)ArcMap的VBA編輯器;或者選擇<Macros>的<Macros>項(xiàng),進(jìn)入如圖2所示Macro對(duì)話框,在“MacroName〞文本框中輸入要?jiǎng)?chuàng)立的宏的名稱,并點(diǎn)<Create>按鈕,啟動(dòng)VBA編輯器。圖1啟動(dòng)Macro對(duì)話框/啟動(dòng)VBA編輯器圖2Macro對(duì)話框2、在圖3所示的窗口中,用戶可以根據(jù)實(shí)際選擇在Normal節(jié)點(diǎn)或者Project節(jié)點(diǎn)的ThisDocument、Forms、Modules中編寫宏〔函數(shù)或過程〕,Normal節(jié)點(diǎn)下所寫的宏系統(tǒng)自動(dòng)保存,除非用戶刪除,否則它將始終存在并在任何工程中都有效;而在Project節(jié)點(diǎn)下所寫得宏隨工程保存〔如不保存工程,則宏也將不被保存〕,并只在工程中有效。圖3VBA編輯器〔VBE〕3、運(yùn)行VBA宏在VBA編輯器中寫好VBA代碼后,有兩種方式運(yùn)行:第一,點(diǎn)擊VBA編輯器工具條中的〔運(yùn)行〕按鈕,可立即運(yùn)行寫好的代碼;第二,退出VBA編輯器,重新啟動(dòng)Macro對(duì)話框,如圖2,選擇要運(yùn)行的VBA宏名稱,點(diǎn)擊<Run>按鈕即可運(yùn)行相應(yīng)的VBA宏。方法二:創(chuàng)立UIControl〔交互式VBA編程〕1、用鼠標(biāo)右擊任何工具欄〔條〕,在彈出的上托式菜單中選擇<Customize>菜單項(xiàng),如圖4,進(jìn)入圖5所示的Customize對(duì)話框。圖4啟動(dòng)“Customize〞對(duì)話框2、切換到“Customize〞對(duì)話框的“mands〞頁,選中“UIControls〞后點(diǎn)擊<NewUIControl>按鈕,進(jìn)入圖6所示的“NewUIControl〞對(duì)話框。3、在“NewUIControl〞對(duì)話框中,用戶可根據(jù)需要選擇UIControl類型:UIButtonControl:創(chuàng)立Button;UIToolControl:創(chuàng)立與Map交互的Tool;UIEditBo*Control:創(chuàng)立EditBo*;UIboBo*Control:創(chuàng)立boBo*。最后點(diǎn)擊<Create>按鈕只創(chuàng)立UIControl或者點(diǎn)擊<CreateandEdit>按鈕創(chuàng)立UIControl并進(jìn)入VBA編輯器。與方法一不同,此時(shí)應(yīng)在UIControl的事件中進(jìn)展VBA編程。圖5Customize對(duì)話框圖6NewUIControl對(duì)話框4、UIControl創(chuàng)立后,在圖5所示的“Customize〞對(duì)話框選中UIControl并將其拖置到任意工具條上,用戶便可象使用系統(tǒng)已有的Control一樣使用所創(chuàng)立的UIControl。如何在VB環(huán)境中利用ArcObjects組件開發(fā)Active*DLL節(jié)討論了如何在ArcGis的VBA環(huán)境中編程,雖然通過這種方式可以完成大多數(shù)用戶的定制需求,但是,在*些情況下,對(duì)于特殊的應(yīng)用,用戶需要脫離ArcGIS環(huán)境而在VB開發(fā)環(huán)境中開發(fā)外部獨(dú)立的應(yīng)用程序,這種外部獨(dú)立的應(yīng)用程序有兩種形式:Active*DLL和StandardE*E。StandardE*E的開發(fā)將在1.1.4中討論,本節(jié)將討論Active*DLL的開發(fā),其關(guān)鍵是引用ArcObjects對(duì)象庫(kù)和實(shí)現(xiàn)ArcObjects接口〔例如Imand,ITool,IToolBar等〕。下面介紹在VB環(huán)境利用ArcObjects組件開發(fā)Active*DLL的一般步驟。1、啟動(dòng)VB開發(fā)環(huán)境,在圖7所示的“NewProject〞對(duì)話框中選擇“Active*DLL〞項(xiàng),并點(diǎn)擊<翻開>按鈕,進(jìn)入VBE環(huán)境。圖7NewProject對(duì)話框2、引用ArcObjects對(duì)象庫(kù):首先點(diǎn)擊<Project>菜單中的<References>項(xiàng),如圖8,進(jìn)入對(duì)象庫(kù)引用對(duì)話框,如圖9。圖8啟動(dòng)對(duì)象庫(kù)引用對(duì)話框圖9對(duì)象庫(kù)引用對(duì)話框3、對(duì)象庫(kù)引用對(duì)話框〔圖9〕中選中“EsriArcMapObjectLibrary〞和“EsriObjectLibrary〞兩項(xiàng),并點(diǎn)擊<OK>按鈕,返回VBE環(huán)境。4、一般在類模塊中寫入實(shí)現(xiàn)特定ArcObjects接口的代碼,如圖10,然后運(yùn)行<File>菜單中的<Makeproject1.dll>項(xiàng),生成DLL文件,如圖11。〔project1.dll隨工程名改變〕。圖10類模塊編輯窗口圖11生成DLL文件如何在ArcMap中加載利用ArcObjects組件開發(fā)的Active*DLL用戶通過中介紹的方法開發(fā)好一個(gè)Active*DLL程序后,便可根據(jù)實(shí)際需要,在ArcMap環(huán)境下加載這個(gè)Active*DLL程序。其一般步驟如下:1、用鼠標(biāo)右擊任何工具欄〔條〕,點(diǎn)擊彈出的上托式菜單中的<Customize>菜單項(xiàng)〔參見圖4〕。2、在Customize對(duì)話框中,根據(jù)被加載DLL的類型切換到“Toolbars〞或者“mands〞頁〔參見圖5〕,然后點(diǎn)擊<AddFromFile>按鈕。3、在“翻開文件〞對(duì)話框中〔Windows通用“翻開文件〞對(duì)話框,圖略〕,選擇被加載的Dll文件,并點(diǎn)擊<翻開>按鈕。4、如果加載是“mands〞,則在圖5所示的對(duì)話框中顯示加載的mand,并可以將其拖置于任何工具條上;如果加載是“ToolBars〞,則在圖12所示的對(duì)話框中顯示加載的ToolBar,選中后即可在ArcMap中顯示。圖12加載ToolBar如何在VB環(huán)境中利用ArcObjects控件開發(fā)E*E利用ArcObjects控件開發(fā)E*E的前三步類似于中開發(fā)“AcrtiveDll〞的前三步,唯一不同的是在“NewProject〞對(duì)話框中選擇“StandardE*E〞。4、點(diǎn)擊<Project>菜單項(xiàng)中的<ponents>項(xiàng),翻開“ponents〞對(duì)話框,如圖13。圖13翻開ponents對(duì)話框5、在“ponents〞對(duì)話框中,切換到Controls頁,并選中“ESRIMapControl〞項(xiàng),點(diǎn)擊<應(yīng)用>或<確定>按鈕,如圖14。圖14ponents對(duì)話框6、如圖15所示,加載MapControl控件之后,在VBE的控件面板中出現(xiàn)了MapControl控件圖標(biāo),用戶便可以象在Form中添加Button一樣在Form中添加MapControl控件,并利用它開發(fā)E*E。圖15添加MapControl控件用戶界面如何創(chuàng)立定制的按鈕(Button)本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的按鈕(Button)。要點(diǎn)用戶通過在類模塊中實(shí)現(xiàn)Imand接口來創(chuàng)立定制的按鈕〔mand〕。Imand接口包括caption、name、category、bitmap、message〔StatusBarr的提示信息〕、tooltip〔微幫助〕、helpconte*tid、helpfile、enabled以及checked等十個(gè)屬性和OnCreate、OnClick兩個(gè)事件。從Imand接口的OnCreate事件中獲取的ArcMap的Application實(shí)例必須用一個(gè)公共變量保存,以便在其它事件中(或者其它接口的事件中甚至整個(gè)工程中)使用?!nCreate事件的參數(shù)hook傳入的是一個(gè)Object,也就是ArcMAP的Application實(shí)例,可把它賦給一個(gè)IApplication接口的變量,便獲得了ArcMAP的實(shí)例?!ぴ贠nClick事件中寫入相關(guān)代碼,表示按下按鈕時(shí)要實(shí)現(xiàn)的功能.程序說明程序在類模塊中實(shí)現(xiàn)Imand接口來創(chuàng)立自己的按鈕(Button)代碼OptionE*plicit'實(shí)現(xiàn)Imand接口ImplementsImandDimm_pPictureasPictureDimm_pApplicationAsIApplicationPrivateSubClass_Initialize()'調(diào)入.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()'參加按下按鈕時(shí)實(shí)現(xiàn)的功能代碼。在這里,'按鈕按下時(shí)顯示ArcMap的Document的TittleDimpDocumentAsIDocumentSetpDocument=m_pApplication.DocumentMsgBo*pDocument.TitleEndSubPrivateSubImand_OnCreate(ByValhookAsObject)'獲取ArcMap的Application實(shí)例Setm_pApplication=hookEndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="CreateButton"EndProperty如何創(chuàng)立定制的Tool本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的Tool要點(diǎn)用戶在類模塊中實(shí)現(xiàn)Imand〔參見〕和ITool接口。ITool接口包括mousemove,mousebuttonpress/release,keyboardkeypress/release,double-click以及rightclick等事件、Cursor屬性和Refresh方法。Tool既具有Button的功能,又具有與ArcMAP界面交互的功能,Button的功能代碼必須寫在Imand的OnClick事件中,而所有實(shí)現(xiàn)交互功能的代碼必須寫在Itool接口的各個(gè)事件中。Itool接口的各個(gè)事件,用戶可以在其中寫入相關(guān)代碼,表示用戶與ArcMAP界面交互時(shí)一旦觸發(fā)*事件要實(shí)現(xiàn)的功能。程序說明程序在類模塊中實(shí)現(xiàn)Imand和Itool接口來創(chuàng)立自己的Tool.代碼OptionE*plicit'實(shí)現(xiàn)Imand和Itool接口ImplementsImandImplementsIToolDimm_pApplicationAsIApplicationDimm_pBitmapAsIPictureDispDimm_pCursorAsIpictureDispPrivateSubClass_Initialize()Setm_pBitmap=LoadResPicture(101,0)'從.RES文件中調(diào)入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()'參加按下按鈕時(shí)實(shí)現(xiàn)的功能代碼MsgBo*"Clickedonmymand"EndSubPrivateSubImand_OnCreate(ByValhookAsObject)'獲取ArcMAP的Application實(shí)例Setm_pApplication=hookEndSubPrivatePropertyGetImand_Tooltip()AsStringImand_Tooltip="MyTool"EndPropertyPrivatePropertyGetITool_Cursor()AsesriCore.OLE_HANDLEITool_Cursor=m_pCursorEndPropertyPrivateFunctionITool_Deactivate()AsBoolean'如果ITool_Deactivate設(shè)為False,則Tool不可用ITool_Deactivate=TrueEndFunctionPrivateFunctionITool_OnConte*tMenu(ByVal*AsLong,ByValYAsLong)AsBoolean'在這里可以參加用戶代碼,點(diǎn)擊Mouse右鍵時(shí)顯示一個(gè)定制的conte*tmenuEndFunctionPrivateSubITool_OnDblClick()'在這里參加Mouse雙擊時(shí)的功能代碼EndSubPrivateSubITool_OnKeyDown(ByValkeyCodeAsLong,ByValShiftAsLong)EndSubPrivateSubITool_OnKeyUp(ByValkeyCodeAsLong,ByValShiftAsLong)EndSubPrivateSubITool_OnMouseDown(ByValButtonAsLong,ByValShiftAsLong,_ByVal*AsLong,ByValYAsLong)'參加Mouse單擊時(shí)的功能代碼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移動(dòng)時(shí)的功能代碼m_pApplication.StatusBar.Message(0)="ITool_OnMouseMove"EndSubPrivateSubITool_OnMouseUp(ByValButtonAsLong,ByValShiftAsLong,_ByVal*AsLong,ByValYAsLong)'參加釋放Mouse時(shí)的功能代碼m_pApplication.StatusBar.Message(0)="ITool_OnMouseUp"EndSubPrivateSubITool_Refresh(ByValhDCAsesriCore.OLE_HANDLE)EndSub如何創(chuàng)立定制的工具條(ToolBar)本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的工具條(ToolBar)。就必須在類模塊中實(shí)現(xiàn)IToolBarDef接口。IToolBarDef接口包括Caption、ItemCount及Name三個(gè)屬性和GetItemInfo方法。要點(diǎn)通過在類模塊中實(shí)現(xiàn)IToolBarDef接口。IToolBarDef接口包括Caption、ItemCount及Name三個(gè)屬性和GetItemInfo方法。·ItemCount屬性表示ToolBar顯示的條目(Button、Tool或其它控件)數(shù)?!etItemInfo方法定義工具條上各條目的CLSID,其中,參數(shù)pos表示條目在ToolBar中的位置,itemDef是定義相應(yīng)位置的條目的IItemDef對(duì)象?!すぞ邨l條目的CLSID分為兩種:1、系統(tǒng)CLSID,代表ArcGIS的一個(gè)功能,其引用方式為"esriCore.命令名稱",如"esriCore.AddDatamand"、"esriCore.FileSavemand"等。2、用戶定制CLSID,表示用戶自己定義的功能。其引用方式為"工程名稱.定制功能類名稱",如"ToolBarDef.ClsBar"。必須注意,這里“定制功能類名稱〞是工程中實(shí)現(xiàn)的一個(gè)功能類名稱,“工程名稱〞即為當(dāng)前工程的名稱〔不是DLL文件名,也不是工具條的名稱〕,每次新建一個(gè)工程時(shí),系統(tǒng)默認(rèn)的工程名在*些情況下無法使用〔在中文版的VB中是一個(gè)亂字符〕,必須改名前方能用。程序說明程序在類模塊中實(shí)現(xiàn)IToolBarDef接口來創(chuàng)立自己的工具條(ToolBar)。代碼OptionE*plicitImplementsIToolBarDefPrivatePropertyGetIToolBarDef_Caption()AsStringIToolBarDef_Caption="CustomToolBar"EndPropertyPrivateSubIToolBarDef_GetItemInfo(ByValposAsLong,ByValitemDefAs_esriCore.IItemDef)'這里假設(shè)在當(dāng)前工程(工程名稱為ToolBarDef)中定義了一個(gè)類模塊(名為ClsBar),'它實(shí)現(xiàn)了Imand接口(可參照)SelectCaseposCase0'用戶自定義條目itemDef.ID="ToolBarDef.ClsBar"itemDef.Group=FalseCase1'系統(tǒng)條目itemDef.ID="esriCore.AddDatamand"itemDef.Group=FalseEndSelectEndSubPrivatePropertyGetIToolBarDef_ItemCount()AsLongIToolBarDef_ItemCount=2EndPropertyPrivatePropertyGetIToolBarDef_Name()AsStringIToolBarDef_Name="CustomToolBar"EndProperty如何創(chuàng)立定制的MultiItem本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的MultiItem。要點(diǎn)需要實(shí)現(xiàn)IMultiItem接口,但不需要同時(shí)實(shí)現(xiàn)Imand接口。IMultiItem接口包括Caption,itemCaption,ItemBitmap,ItemEnabled,ItemChecked,Message及Name等屬性和OnItemClick,OnPopup事件?!temCaption,ItemBitmap,ItemEnabled,ItemChecked等屬性的參數(shù)inde*表示當(dāng)前Item的下標(biāo)索引?!nPopup事件的參數(shù)hook同Imand接口的OnCreate事件的參數(shù)hook一樣,傳入ArcGIS的Application實(shí)例,同時(shí),該事件返回將要顯示的Item數(shù)目。·OnItemClick事件的參數(shù)Inde*表示用戶當(dāng)前點(diǎn)擊的Item的索引,用戶根據(jù)該索引分別定義點(diǎn)擊各個(gè)Item時(shí)實(shí)現(xiàn)的功能。程序說明程序在類模塊中實(shí)現(xiàn)IMultiItem接口來創(chuàng)立定制自己的MultiItem。代碼OptionE*plicitImplementsIMultiItemPrivatem_pAppAsIApplication'ArcMap的DocumentPrivatem_pM*DocAsIM*Document'當(dāng)前FocusMapPrivatem_pMapAsIMap'Map中的層數(shù)Privatem_pLayertAsLongPrivatePropertyGetIMultiItem_Caption()AsStringIMultiItem_Caption="ZoomToLayers"EndPropertyPrivatePropertyGetIMultiItem_HelpConte*tID()AsLongEndPropertyPrivatePropertyGetIMultiItem_HelpFile()AsStringEndPropertyPrivatePropertyGetIMultiItem_ItemBitmap(ByValInde*AsLong)AsesriCore.OLE_HANDLEEndPropertyPrivatePropertyGetIMultiItem_ItemCaption(ByValInde*AsLong)AsStringDimiAsInteger'遍歷每一個(gè)層Fori=0Tom_pLayert-1'如果層號(hào)與當(dāng)前Item的Inde*一樣,就設(shè)置該Item的CaptionIfInde*=iThenIMultiItem_ItemCaption="Zoomto"&m_pMap.Layer(i).NameEndIfNe*tEndPropertyPrivatePropertyGetIMultiItem_ItemChecked(ByValInde*AsLong)AsBooleanEndPropertyPrivatePropertyGetIMultiItem_ItemEnabled(ByValInde*AsLong)AsBooleanDimiAsInteger'遍歷每一個(gè)層Fori=0Tom_pLayert-1'如果層號(hào)與當(dāng)前Item的Inde*一樣,則當(dāng)前Item的Enable根據(jù)該層的Visible設(shè)置。IfInde*=iThenIfm_pMap.Layer(i).VisibleThenIMultiItem_ItemEnabled=TrueEndIfEndIfNe*tEndPropertyPrivatePropertyGetIMultiItem_Message()AsStringIMultiItem_Message="Zoomstothelayer."EndPropertyPrivatePropertyGetIMultiItem_Name()AsStringIMultiItem_Name="ZoomMulti"EndPropertyPrivateSubIMultiItem_OnItemClick(ByValInde*AsLong)DimiAsIntegerDimpEnvAsIEnvelopeDimm_BookMarkAsIAOIBookmark'遍歷每一個(gè)層Fori=0Tom_pLayert–1'如果層號(hào)與當(dāng)前Item的Inde*一樣,則以該層的AreaOfInterest為*圍執(zhí)行ZoomIfInde*=iThenSetpEnv=m_pMap.Layer(i).AreaOfInterestSetm_BookMark=NewAOIBookmarkSetm_BookMark.Location=pEnvm_BookMark.ZoomTom_pMapEndIfNe*tEndSubPrivateFunctionIMultiItem_OnPopup(ByValhookAsObject)AsLongSetm_pApp=hook'獲取Map中的層數(shù)Setm_pM*Doc=m_pApp.DocumentSetm_pMap=m_pM*Doc.FocusMapm_pLayert=m_pMap.LayerCount'顯示的Item數(shù)等于層數(shù)IMultiItem_OnPopup=m_pLayertEndFunction如何創(chuàng)立定制的菜單(Menu)本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的菜單(Menu)。要點(diǎn)用戶通過在類模塊中實(shí)現(xiàn)IMenuDef接口來創(chuàng)立定制的菜單(Menu),如果要使菜單出現(xiàn)在CustomizeDialog的Menus類型中,必須同時(shí)實(shí)現(xiàn)IrootLevelMenu接口,它說明菜單為rootmenu。IMenuDef接口包括Caption、ItemCount及Name三個(gè)屬性和GetItemInfo方法。類似IToolBarDef(參照)程序說明程序在類模塊中實(shí)現(xiàn)IMenuDef接口來創(chuàng)立定制的菜單(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如何創(chuàng)立定制的ToolControl本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的ToolControl。ToolControl是指具有boBo*的下拉列表或EditBo*的編輯功能的一類控件。要?jiǎng)?chuàng)立定制的ToolControl,必須在類模塊中實(shí)現(xiàn)Imand和IToolControl接口。IToolControl接口包括hWnd屬性和OnDrop,OnFocus事件。要點(diǎn)·IToolControl接口的hWnd屬性,承受一個(gè)WindowHandle?!ToolControl接口的OnDrop事件,支持ToolControl的拖放,傳入?yún)?shù)barType表示Bar類型?!ToolControl接口的OnFocus事件,傳入IpletionNotify類型的參數(shù)plete,可以通過執(zhí)行IpletionNotify接口的Setplete方法告之ArcMAP,ToolControl可以失去Focus。程序說明本例中涉及三個(gè)模塊,詳細(xì)描述如下,其中,在類模塊中實(shí)現(xiàn)了IToolBarDef接口來創(chuàng)立自己的ToolControl。代碼'1、frmImagebo.frm模塊,定義選中bo**一項(xiàng)之后實(shí)現(xiàn)的功能。要求在Form上放置一個(gè)'Imageb控件〔名為Imagebo1〕和一個(gè)ImageList控件〔名為ImageList1〕,并在ImageList1'中添加三*圖片。PrivateSubForm_Load()'設(shè)置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'設(shè)置顏色DimpRgbColorAsIrgbColorSetpRgbColor=NewRgbColorpRgbColor.RGB=color'改變選中局部的顏色DimpSelectionEnvironmentAsISelectionEnvironmentSetpSelectionEnvironment=NewSelectionEnvironmentSetpSelectionEnvironment.DefaultColor=pRgbColor'刷新視圖'通知ArcMap,ToolControl現(xiàn)在可以失去Focusg_ppletionNotify.SetpleteEndSub'2、modPublicVars.bas模塊,定義工程中用到的全局變量。OptionE*plicitPublicg_pApplicationAsIApplicationPublicg_ppletionNotifyAsIpletionNotify'3、CustImagebo.cls模塊,實(shí)現(xiàn)接口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如何創(chuàng)立定、使用制的可??看翱?DockableWindow)本例要實(shí)現(xiàn)的是如何創(chuàng)立定制的可??看翱?DockableWindow)要點(diǎn)用戶通過在類模塊中實(shí)現(xiàn)IDockableWindowDef接口來創(chuàng)立定制的可停靠窗口(DockableWindow)。IDockableWindowDef接口包括Caption、ChildHWND,UserData及Name等屬性和OnCreate、OnDestroy事件?!hildHWND屬性表示可??看翱诎腤indow的Handle?!nCreate事件的參數(shù)hook傳入ArcGIS的Application實(shí)例?!?chuàng)立并注冊(cè)可??看翱诘牟襟E:1、實(shí)現(xiàn)IdockableWindowDef接口(參見實(shí)例);2、編譯成DLL;3、調(diào)用windows目錄下system32子目錄下的regsvr32.e*e用下面的形式注冊(cè)編譯好的DLL:win目錄\system32\regsvr32.e*e<路徑>\<文件名>.dll4、運(yùn)行<arcmap目錄>\arce*e81\Bin\categories.e*e,在翻開的ponentCatregoryManager中找到ESRIM*DockableWindow,點(diǎn)擊AddObject…按鈕將上面注冊(cè)的DLL文件參加,并選中實(shí)現(xiàn)IdockableWindowDef接口的類名即可。程序說明類模塊ClsDockableWindow只是創(chuàng)立與注冊(cè)可??看翱?,但還不能用,還必須定義一個(gè)IdockableWindow接口的變量引用注冊(cè)的類〔必須用IdockableWindowsManager接口的GetDockableWindow獲取,其ID號(hào)用"實(shí)現(xiàn)IdockableWindowDef接口的工程名project1.實(shí)現(xiàn)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如何創(chuàng)立、使用定制的E*tension本例要實(shí)現(xiàn)的是如何創(chuàng)立、使用定制的E*tension。要點(diǎn)用戶需要實(shí)現(xiàn)IE*tension接口來創(chuàng)立定制的E*tension。IE*tension接口包括Name屬性和startup和shutdown事件?!?chuàng)立并注冊(cè)E*tension的步驟:1.實(shí)現(xiàn)IE*tension接口;2.編譯成DLL;3.調(diào)用windows目錄下system32子目錄下的regsvr32.e*e用下面的形式注冊(cè)編譯好的DLLwin目錄\system32\regsvr32.e*e<路徑>\<文件名>.dll4.運(yùn)行<arcmap目錄>\arce*e81\Bin\categories.e*e,在翻開的ponentCatregoryManager中找到ESRIM*E*tensions,點(diǎn)擊AddObject…按鈕將上面注冊(cè)的DLL文件參加,并選中實(shí)現(xiàn)IE*tension接口的類名即可。程序說明用戶通過在類模塊中實(shí)現(xiàn)IE*tension接口來創(chuàng)立定制的E*tension。E*tension將在ArcMap翻開時(shí)自動(dòng)加載,在ArcMap關(guān)閉時(shí)自動(dòng)卸載。代碼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如何使用狀態(tài)條(StatusBar)與進(jìn)度條(ProgressBar)本例要演示的是如何使用狀態(tài)條(StatusBar)與進(jìn)度條(ProgressBar)。實(shí)現(xiàn)后的結(jié)果為在ArcMap中,狀態(tài)條位于其底部,它顯示ArcMAP當(dāng)前狀態(tài)的信息,包含進(jìn)度條。要點(diǎn)一般情況下,通過ArcMAP的Application實(shí)例獲取IstatusBar的實(shí)例,然后再通過StatusBar獲取IprogressBar的實(shí)例,并將IprogressBar的實(shí)例賦給IstepProgressor類型的變量。程序說明運(yùn)行函數(shù)ShowProgress將在ArcMap的下方添加一個(gè)狀態(tài)條(StatusBar)和進(jìn)度條(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"用戶根據(jù)實(shí)際而改變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的對(duì)話框添加對(duì)話框可以通過相應(yīng)的接口實(shí)現(xiàn)。比方“添加數(shù)據(jù)對(duì)話框〞使用IaddDataDialog接口,“生成點(diǎn)坐標(biāo)對(duì)話框〞使用ICoordinateDialog接口,“生成字符串對(duì)話框〞使用IGetStringDialog接口,“生成數(shù)值對(duì)話框〞使用INumberDialog接口等等。本例以添加數(shù)據(jù)對(duì)話框(AddDataDialog)為例,講述對(duì)話框是如何通過接口實(shí)現(xiàn)添加的。要點(diǎn)用戶通過實(shí)現(xiàn)IaddDataDialog接口來創(chuàng)立定制的添加數(shù)據(jù)對(duì)話框,IaddDataDialog接口包括Document和Map屬性和Show事件。程序說明在程序中除了必須生成IaddDataDialog接口的實(shí)例外,還必須指定對(duì)話框的Document和Map。當(dāng)為AddDataDialog指定Document和Map之后,系統(tǒng)會(huì)自動(dòng)將用戶選擇的數(shù)據(jù)參加到指定Document和Map中。最后實(shí)現(xiàn)在ArcMap中添加數(shù)據(jù)的對(duì)話框。代碼SubShowProgress()DimmDocumentAsIM*DocumentDimmAddDataDialogAsIAddDataDialogSetmAddDataDialog=NewAddDataDialogSetmDocument=ThisDocumentmAddDataDialog.Document=mDocumentmAddDataDialog.Map=mDocument.FocusMapmAddDataDialog.ShowApplication.hWnd,TrueEndSub如何調(diào)用ArcMap中現(xiàn)有的功能如何調(diào)用ArcMap中現(xiàn)有的功能,比方菜單欄、工具欄中的*些功能。這些都可以通過UID來實(shí)現(xiàn)。本例是通過UID調(diào)用“另存為〞功能??梢酝ㄟ^兩種方法得到UID:方法一:運(yùn)用ArcID模塊要點(diǎn)通過ArcID獲得UID,ArcID是ArcMap的VBA中的模塊。只需要知道要調(diào)用功能的名稱運(yùn)用代碼就可以實(shí)現(xiàn)。程序說明程序通過運(yùn)用ArcID模塊和命令名稱來實(shí)現(xiàn)調(diào)用“另存為〞的功能。代碼SubE*ecuteCmd()DimpmandItemAsImandItem'UseArcIDmoduleandtheNameoftheSaveAsmandSetpmandItem=Application.Document.mandBars.Find(arcid.File_SaveAs)pmandItem.E*ecuteEndSub方法二:直接寫代碼要點(diǎn)通過直接寫代碼獲得UID實(shí)現(xiàn)調(diào)用功能。程序說明寫入文件菜單項(xiàng)的GUID(CLSID或ProgID)來調(diào)用文件菜單項(xiàng),同時(shí)還需要通過設(shè)置Subtype的值來調(diào)用文件菜單項(xiàng)的“另存為〞功能。代碼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如何創(chuàng)立放大鏡(蟲眼)本例要實(shí)現(xiàn)的是如何創(chuàng)立放大鏡(蟲眼),將所選區(qū)域放大一定的倍數(shù)。要點(diǎn)用戶通過定義IMapInset、IMapInsetWindow、IDataWindowFactory三個(gè)接口,運(yùn)用它們的方法、屬性來創(chuàng)立放大鏡(蟲眼)。程序說明運(yùn)用這個(gè)子程序生成了一個(gè)新的放大鏡窗口,在本例中將放大率設(shè)定為200%代替原來的400%。代碼PublicSubCreateMagnifierWindow()DimpMapInsetAsIMapInsetDimpMapInsetWindowAsIMapInsetWindowDimpDataWindowFactoryAsIDataWindowFactorySetpDataWindowFactory=NewMapInsetWindowFactoryIfpDataWindowFactory.CanCreate(Application)ThenSetpMapInsetWindow=pDataWindowFactory.Create(Application)SetpMapInset=pMapInsetWindow.MapInset'Setthezoompercentto200%pMapInset.ZoomPercent=200pMapInsetWindow.ShowTrueEndIfEndSubGeoDataBase如何加載Shape文件本例實(shí)現(xiàn)的是在ArcMap中連接指定的Shape文件,并將其加載到當(dāng)前激活的Map中。要點(diǎn)通過FeatureLayer類實(shí)現(xiàn)IFeatureLayer接口對(duì)象,設(shè)置IFeatureLayer.FeatureClass屬性和Name屬性,使用IMap.AddLayer方法將新層添加到當(dāng)前地圖。利用IWorkspaceFacktory接口、IFeatureWorkspace接口和IFeatureLayer接口實(shí)現(xiàn)連接Shape文件程序說明函數(shù)OpenShapeFile根據(jù)輸入的Shape文件路徑sFilePath,將文件名為sFileName的Shape文件連接到當(dāng)前激活的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文件本例實(shí)現(xiàn)的是如何在當(dāng)前的ArcMap中參加Te*t文件和dBASE文件。要點(diǎn)首先為Te*t文件或dBASE文件創(chuàng)立一個(gè)與之對(duì)應(yīng)的ITable接口對(duì)象,然后通過IMap實(shí)例獲得IStandaloneTable接口對(duì)象和IStandaloneTableCollection接口對(duì)象,并設(shè)置其屬性,最后使用IStandaloneTableCollection.AddStandaloneTable方法將Te*t文件或dBASE文件參加到當(dāng)前的ArcMap中。參加Te*t文件或dBASE文件的區(qū)別僅在于創(chuàng)立ITable對(duì)象時(shí)IWorkspaceFactory的類型不同,參加Te*t文件時(shí)是Te*tFileWorkspaceFactory類型,參加dBASE文件時(shí)是ShapefileWorkspaceFacto

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論