ArcGIS Developer Help  (System)    

IExtension Example

[Visual Basic 6.0]

The following class module demonstrates how to create a custom ArcMap extension that can perform some action when the document events occur.
When this extension is loaded, a message box is displayed when a new document is created and when a document is opened.

How to use:

  1. Import this class module into an ActiveX DLL Visual Basic project.
  2. Add a reference to the ESRI System Library (esriSystem.olb).
  3. Save and compile the project.
  4. Add the extension to the ESRI Mx Extensions category using Categories.exe.
  5. Start ArcMap and take note of when you receive message boxes.
 '=======================================================
 Option Explicit
 Implements IExtension
 
 Dim m_pApp As IApplication
 ' Need to listen for the MxDocument events
 Dim WithEvents m_pDoc As MxDocument
 
 Private Property Get IExtension_Name() As String
     IExtension_Name = "My Extension"
 End Property
 
 Private Sub IExtension_Shutdown()
     ' Clear the reference to the Application and MxDocument
     Set m_pApp = Nothing
     Set m_pDoc = Nothing
 End Sub
 
 Private Sub IExtension_Startup(initializationData As Variant)
     ' This extension is an ArcMap Extension. When this extension in loaded on
     ' ArcMap startup, initializationData is passed in as a reference to the
     ' Application object
     Set m_pApp = initializationData
     
     'Start listening for the MxDocument events.
     Set m_pDoc = m_pApp.Document
 End Sub
 
 Private Function m_pDoc_NewDocument() As Boolean
     ' Do something when a new document is created
     MsgBox "Creating a new document."
 End Function
 
 Private Function m_pDoc_OpenDocument() As Boolean
     ' So something when a document is opened.
     MsgBox "Opening a document"
 End Function
 

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.