Shape Name Utility
The Shape Name Utility is a simple utility developed by Richard Marsden that allows a user to examine
and/or change the names of MapPoint shapes. This article describes the
code and how it works.
The Shape Name Utility has been released as freeware and as open source
under the Berkeley license. An installer, and a source code archive can
both be downloaded from the Mapping-Tools.com website at:
http://www.mapping-tools.com/shapename/index.shtml
The following source code description can be used as a form of tutorial
for those who want to build a MapPoint add-in using Visual Basic 6. As
well as Visual Basic 6, the project uses NSIS for building the
installer, and Help & Manual for the documentation. NSIS is open source,
but Help & Manual is a commercial system. Both are good products, but
you do not need either of them in order to build the project and to
install it on your development PC. After saying this, it is strongly
recommended that you use an installer if you wish to distribute your
add-in on multiple PCs.
Project Files
The Shape Name Utility has been written using Visual Basic 6. Although this getting old, it is good for quick MapPoint development, and is widely available. You will need Visual Studio 6 to build the Shape Name Utility files.
The installer is an NSIS script. NSIS is a powerful open source scripting system for building installers. It includes support for registry modification and DLL version updates - both of which are essential for a MapPoint add-in.
The PDF manual is built using Help & Manual v4.5. Help & Manual is a commercial help authoring system, but is very powerful and easy to use.
The source code is split amongst three files. frmAbout.frm, frmShape.frm, and Connect.dsr. frmAbout.frm is the standard VB6 About Box but with the default text fields filled out. The other two files are explained on the next two pages.
Connect.dsr
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:
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.
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.
frmShape.frm
frmShape.frm is a VB6 form file that implements the main Shape Name Utility modal dialog box. It also manages the shape name query and update. The form is visually defined to look like this:

There are four global variables defined for the form. oApp and oMap define references to the MapPoint Application and Map. sName stores the name that was read from the current shape. bReadonly indicates if the name is read only (and should not be updated).
There are four methods, three of which are button call-backs.
AboutButton_Click
This is called when the user clicks the About button. It creates an About box (frmAbout) and opens it as a dialog box. frmAbout is implemented as a standard VB6-produced About box.
CancelButton_Click
This is called when the user clicks the Cancel button. It simply closes the frmShape modal dialog box.
OKButton_Click
This is called when the user clicks the OK button. If saves any name change (if possible), and then closes the frmShape modal dialog box. Note that the new name is trimmed (leading and trailing spaces are removed) and compared against the stored copy of the shape name to check if it has changed.
DisplayForm
This is called by the Tools menu callback, to query the selected object's name and to display the form. Warning dialog boxes are displayed if an object is not selected, or if the object is not a shape or a pushpin. The name is read for both shape and pushpin selections, but pushpins are marked as readonly.
If the object is a shape, then the shape type is queried. Both the name and the type are displayed in the dialog before it is finally displayed.
Prior to Winwaed, Richard worked as a software developer working on
seismic processing algorithms for the oil exploration industry. He holds
geology and geophysics degrees from the University of Cambridge
(Churchill College), and the University of Durham; and an
interdisciplinary MBA from the University of Dallas.