Copyright©2004ESRI.Allrightsreserved.DevelopingApplicationswithArcGISEngine控件的定制和扩展5-2DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.课5概述ToolbarControl框架定制命令和工具定制COM命令,工具,工具条,和菜单定制COM扩展定制对话框ToolbarMenus5-3DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.定制和扩展的类型可以有多种不同定制方法允许用户在运行时增加和移除命令(通过CustomizeDialog)自动保存和加载命令到工具条上运行时创建和显示菜单可以实现不同的扩展创建定制的命令,工具,菜单,和工具条定制扩展MapControlToolbarTOCToolToolRead/WriteApplicationDataToolToolMenuMenu5-4DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ToolbarControl框架ToolbarControlToolbarItemsCommandPoolToolBarMenuToolbarItemsCommandPoolCustomizeDialog5-5DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ToolbarItems工具条项目ToolbarControl为每一个加载的项创建一个ToolbarItem类用于管理相应的项目项目类别命令,工具,工具控件,和工具条菜单5-6DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.CommandPool命令池管理命令的集合只有两个对象直接访问命令池ToolbarControlToolbarMenu提供低水平的访问ICommandPool::CreatedICommandPool::ExistsICommandPoolEdit::CallOnCreateICommandPoolEdit::Hook开发者通常不使用5-7DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.项目怎样被加载到命令池中方法1:传递一个新命令对象的实例NewCommandItemiscreatedforthisobjectNotshared方法2:传递命令的UIDNewCommandItemiscreatedifitdoesnotexistAllreferenceswillsharetheinstanceDimpUidAsNewesriSystem.UIDpUid.Value=esriControlCommands.ControlsMapZoomInToolToolbarControl1.AddItempUid,0,-1,True,,esriCommandStyleIconAndTextDimpUidAsNewesriSystem.UIDpUid.Value=esriControlCommands.ControlsMapZoomInToolToolbarControl1.AddItempUid,0,-1,True,,esriCommandStyleIconAndTextDimcommandasICommand=NewesriControlCommands.ControlsMapZoomInToolToolbarControl1.AddItemcommand,0,-1,True,,esriCommandStyleIconAndTextDimcommandasICommand=NewesriControlCommands.ControlsMapZoomInToolToolbarControl1.AddItemcommand,0,-1,True,,esriCommandStyleIconAndText5-8DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ToolbarControl命令创建过程每一项被加载到命令池ToolbarisinitializedPoolispopulatedCommandPoolCmdCmdIToolbarItemIToolbarItemCmd1IToolbarItemTool2IToolbarItemMenu3ItemsareaddedCommand,toolormenuiscreatedUpdateInterval5-9DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ToolbarItems和CommandsToolbarItems封装了commandsIToolbarItemCommand:提供对command的访问Style:控制command的风格UID:command的全局唯一ID号DimtoolbarItemAsIToolbarItemFori=0ToAxToolbarControl1.Count-1toolbarItem=AxToolbarControl1.GetItem(i)DimcommandasICommandcommand=toolbarItem.CommandMsgBox(command.Name&toolbarItem.Style&toolbarItem.UID.Value)NextDimtoolbarItemAsIToolbarItemFori=0ToAxToolbarControl1.Count-1toolbarItem=AxToolbarControl1.GetItem(i)DimcommandasICommandcommand=toolbarItem.CommandMsgBox(command.Name&toolbarItem.Style&toolbarItem.UID.Value)Next5-10DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.实现定制命令框架提供了创建自定义command的机制无缝地加载到ToolbarControl作为一个CommandItem加载外观和行为和其它项一样执行任何ArcObjects代码步骤1.创建一个类2.实现ICommand3.将类加载到工具条上PublicClassZoomToLayerClassImplementsICommandPublicClassZoomToLayerClassImplementsICommand5-11DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.定制命令:属性设置当command被创建属性就可存取属性ICommandNameCaptionCategoryTooltipMessageBitmapHelpContextHelpFilePublicReadOnlyPropertyBitmap()AsIntegerImplementsESRI.ArcGIS.SystemUI.ICommand.BitmapGetreturnm_bitmapEndGetEndPropertyPublicReadOnlyPropertyCaption()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.CaptionGetreturnIdentifyEndGetEndPropertyPublicReadOnlyPropertyCategory()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.CategoryGetreturnDAAECommandsEndGetEndPropertyPublicReadOnlyPropertyName()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.NameGetreturnDAAECustomCommand_IdentifyEndGetEndPropertyPublicReadOnlyPropertyBitmap()AsIntegerImplementsESRI.ArcGIS.SystemUI.ICommand.BitmapGetreturnm_bitmapEndGetEndPropertyPublicReadOnlyPropertyCaption()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.CaptionGetreturnIdentifyEndGetEndPropertyPublicReadOnlyPropertyCategory()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.CategoryGetreturnDAAECommandsEndGetEndPropertyPublicReadOnlyPropertyName()AsStringImplementsESRI.ArcGIS.SystemUI.ICommand.NameGetreturnDAAECustomCommand_IdentifyEndGetEndProperty5-12DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.定制命令:访问hook(钩子)对象Hook(钩子)是一个对创建command的对象的向后引用可以是不同的对象ToolbarControl,MapControl,PageLayoutControl,…当command创建的时候传递进来ICommandOnCreatePrivateSubICommand_OnCreate(ByValhookAsObject)If(TypeOfhookIsesriToolbarControl.IToolbarControl)ThenDimToolBarConAsesriToolbarControl.IToolbarControlSetToolBarCon=hookIf(TypeOfToolBarCon.BuddyisMapControl)ThenDimmapControlasIMapControlSetMapControl=ToolBarCon.BuddySetm_map=mapControl.MapEndIfElseIf(TypeOfhookisIMapControl3)thenDimmapControlasIMapControlSetmapControl=hookSetm_map=mapControl.MapEndIfEndSubPrivateSubICommand_OnCreate(ByValhookAsObject)If(TypeOfhookIsesriToolbarControl.IToolbarControl)The