|
Source Code: Connect.dsr |
Top Previous Next |
|
The Connect.dsr is based on the file produced by the VB6 Add-in Wizard. It manages the add-in for MapPoint, by controlling the menu item and the menu callback.
There are two global variables (oApp and oFrm) which hold references to the parent MapPoint application and our form, respectively.
There are only three methods:
AddinInstance_MenuClick
This subroutine is called when the user clicks the Shape Name Utility menu item. It creates a new form object if we do not have one, and then calls the form's DisplayForm method. This method queries the selected shape and displays the form as a modal dialog box. Here is the code:
Public Sub AddinInstance_MenuClick() If (oFrm Is Nothing) Then Set oFrm = New frmShape End If Call oFrm.DisplayForm(oApp) End Sub
AddinInstance_OnConnection
This method is a part of the standard add-in interface. It is called by MapPoint when it loads the Shape Name Utility add-in and connects to it.
Our implementation stores a reference to the parent application for future use, and adds our menu item ("Shape Name Utility...") to the Tools menu. This is connected to the AddinInstance_MenuCheck method, above.
' MapPoint calls this method when it loads the AddIn and first connects to it ' We add the menu item here Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant) ' Display an error and finish, if we have an error On Error GoTo error_handler
' Keep a reference to the MapPoint object ' This will then be available when we need it Set oApp = Application
' Add the menu item. Menu text will say "Circle Demo..." ' Clicking the menu item calls the RunDemo method on this object (defined above) oApp.AddCommand "Shape Name Utility...", "AddinInstance_MenuClick", Me
' Done! Exit Sub
error_handler: ' All errors jump to here ' Display the error in a simple dialog box MsgBox Err.Description
End Sub
AddinInstance_OnDisconnection
This method is also a part of the standard add-in interface. It is called when MapPoint is disconnecting and unloading the add-in from memory. We remove our menu item from the Tools menu, and clear our global references.
' This method removes the add-in from MapPoint ' It is called when MapPoint is closing and/or is disconnecting the add-in Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant) ' Keep going if we have an error On Error Resume Next
' Remove all menu items and other call-backs oApp.RemoveCommands Me
' Good hygiene Set oApp = Nothing Set oFrm = Nothing End Sub
|