How to programmatically perform identification


Identifying features, raster cells, etc, is simplified by the IdentifyDialog object. This sample, along with the standard Identify Tool on the Tools toolbar, uses the IdentifyDialog object to perform identification. The benefit of the IdentifyDialog object is that it automatically performs the search on a layer and populates a standard dialog with the results.

How to use

  1. Add a new UIToolControl to any toolbar.
  2. Paste the code into the UIToolControl's mouse down event.
  3. Completely close down VBA so that mouse events will fire.
  4. Select the tool and start identifying.
[VBA]
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    Dim pMxDoc As IMxDocument
    Dim pActiveView As IActiveView
    Dim pIdentifyDialog As IIdentifyDialog
    Dim pIdentifyDialogProps As IIdentifyDialogProps
    Dim pEnumLayer As IEnumLayer
    Dim pLayer As ILayer
    
    Set pMxDoc = Application.Document
    Set pActiveView = pMxDoc.FocusMap
    
    'Create a new IdentifyDialog and associate it
    'with the focus map and the map's display
    Set pIdentifyDialog = New IdentifyDialog
    Set pIdentifyDialogProps = pIdentifyDialog 'QI
    Set pIdentifyDialog.Map = pMxDoc.FocusMap
    Set pIdentifyDialog.Display = pActiveView.ScreenDisplay
    
    'Clear the dialog on each mouse click
    pIdentifyDialog.ClearLayers
    
    'Perform an identify on all of the layers the dialog
    'says are searchable
    Set pEnumLayer = pIdentifyDialogProps.Layers
    pEnumLayer.Reset
    Set pLayer = pEnumLayer.Next
    Do While Not pLayer Is Nothing
        pIdentifyDialog.AddLayerIdentifyPoint pLayer, x, y
        Set pLayer = pEnumLayer.Next
    Loop
    
    pIdentifyDialog.Show
    
End Sub