Sie sind auf Seite 1von 3

PopupMenu

Description: This sample demonstrates creating a popup menu and uses the ToolbarControl in conjunction with the MapControl and Control Commands.
class module
Option Explicit Implements IMenuDef Private Property Get IMenuDef_Caption() As String IMenuDef_Caption = "Navigation" End Property Private Sub IMenuDef_GetItemInfo(ByVal pos As Long, ByVal itemDef As esriSystemUI.IItemDef) Select Case pos 'Commands for the menu Case 0 itemDef.ID = "esriControlCommands.ControlsMapZoomInFixedCommand" Case 1 itemDef.ID = "esriControlCommands.ControlsMapZoomOutFixedCommand" Case 2 itemDef.ID = "esriControlCommands.ControlsMapFullExtentCommand" Case 3 itemDef.ID = "esriControlCommands.ControlsMapZoomToLastExtentBackCommand" itemDef.Group = True Case 4 itemDef.ID = "esriControlCommands.ControlsMapZoomToLastExtentForwardCommand" End Select End Sub Private Property Get IMenuDef_ItemCount() As Long IMenuDef_ItemCount = 5 End Property Private Property Get IMenuDef_Name() As String IMenuDef_Name = "Navigation" End Property

form file

Option Explicit

Private m_pAoInitialize As IAoInitialize Private m_pToolbarMenu As IToolbarMenu Private Sub Form_Load() 'Initialize the application If CheckOutLicenses(esriLicenseProductCodeEngine) <> esriLicenseCheckedOut Then If CheckOutLicenses(esriLicenseProductCodeArcView) <> esriLicenseCheckedOut Then If CheckOutLicenses(esriLicenseProductCodeArcEditor) <> esriLicenseCheckedOut Then If CheckOutLicenses(esriLicenseProductCodeArcInfo) <> esriLicenseCheckedOut Then MsgBox "The initialization failed. This application cannot run!" Unload Form1 Exit Sub End If End If End If End If 'Set buddy control ToolbarControl1.SetBuddyControl MapControl1 'Create UID's and add new items to the ToolbarControl Dim pUid As New UID pUid.Value = "esriControlCommands.ControlsOpenDocCommand" ToolbarControl1.AddItem pUid, 0, 0, False, , esriCommandStyleIconAndText pUid.Value = "esriControlCommands.ControlsMapZoomInTool" ToolbarControl1.AddItem pUid, , , True, , esriCommandStyleIconAndText pUid.Value = "esriControlCommands.ControlsMapZoomOutTool" ToolbarControl1.AddItem pUid, , , , , esriCommandStyleIconAndText pUid.Value = "esriControlCommands.ControlsMapPanTool" ToolbarControl1.AddItem pUid, , , , , esriCommandStyleIconAndText pUid.Value = "esriControlCommands.ControlsMapFullExtentCommand" ToolbarControl1.AddItem pUid, , , , , esriCommandStyleIconAndText 'Create a MenuDef object Dim pMenuDef As esriSystemUI.IMenuDef Set pMenuDef = New NavigationMenu 'Create a new ToolbarMenu Set m_pToolbarMenu = New ToolbarMenu 'Add the MenuDef to the ToolbarMenu m_pToolbarMenu.AddItem pMenuDef 'Set the Toolbarmenu's hook m_pToolbarMenu.SetHook ToolbarControl1.Object End Sub Private Sub Form_Unload(Cancel As Integer) 'Shut down the AoInitilaize object m_pAoInitialize.Shutdown End Sub Private Sub MapControl1_OnMouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByVal mapX As Double, ByVal mapY As Double)

If button = vbRightButton Then 'Popup the menu m_pToolbarMenu.PopupMenu x, y, MapControl1.hWnd End If End Sub Private Function CheckOutLicenses(productCode As esriLicenseProductCode) As esriLicenseStatus Dim licenseStatus As esriLicenseStatus licenseStatus = esriLicenseUnavailable Set m_pAoInitialize = New AoInitialize If m_pAoInitialize Is Nothing Then CheckOutLicenses = licenseStatus 'Determine if the product is available licenseStatus = m_pAoInitialize.IsProductCodeAvailable(productCode) If (licenseStatus = esriLicenseAvailable) Then licenseStatus = m_pAoInitialize.Initialize(productCode) End If CheckOutLicenses = licenseStatus End Function

Das könnte Ihnen auch gefallen