Please let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!
After my recent tip on using Visio drawings and data in the Visual Studio environment, I received various reader e-mails asking for similar pointers on other Microsoft applications as well. Let me address this subject generally first, and then specifically for MapPoint 2002 to answer a query from reader Phil Wyatt on that particular subject.
To begin with, many Microsoft applications also include ActiveX controls designed to access, display and sometimes even to manipulate data formatted using those applications. The key to finding these incredibly helpful widgets is to do a bit of sleuthing on Microsoft Technet or in the MSDN (Microsoft Developer Network) Web pages, seeking a combination of the application name and the term "ActiveX control." Though functionality and capability varies from application to application -- as you'll see in this tip for MapPoint -- some kind of access and display capability is normally available for use in Visual Studio applications, to help developers make the most of Microsoft tools and technologies.
When is comes to the MapPoint control, for example, it provides access to a subset of the program's functionality. It's not possible to save a map directly into HTML format with the ActiveX control, but it is possible to save a map using MapPoint's intrinsic .ptm file format, then to use code to open that file inside the MapPoint application and save it into HTML from there. My take on some of these limitations is that they're intended to make legitimate ownership of the application necessary to make full use of its capabilities. This is not an unreasonable requirement, and certainly makes sense from a company that, like Microsoft, seeks to make money from selling its applications!
Microsoft Knowledge Base article Q302897 explains how to automate the MapPoint 2002 ActiveX control and save a map in HTML format using Visual Basic .NET. Here are the high points of that detailed, step-by-step description:
- Inside VS.NET use the File menu's New entry, then click Project. Under the Project types entry, select Visual Basic Projects, then click Windows Application under the Templates entry.
- When the New Project dialog box appears, name that project MapPointControl, then click OK. This creates a VB.NET form named Form1 by default.
- From the Visual Basic menu, click View, then Toolbox.
- From the Tools menu, click Customize Toolbox; in the resulting dialog box, pick Microsoft MapPoint Control 9.0 from the component list and click OK. Note: the control now appears in the Toolbox near the end of the Windows Form controls part of that list.
- To Form1 add three buttons (named Button1, Button2, and Button3 by default) and a MapPoint control so that it fills most of the form's frame. Change the Text properties for the three buttons to Make Route Map, Save as HTML, and Close the Project (1, 2, and 3 respectively).
- Double-click Form1 to display its Load event handler. Replace the code that reads
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub
with the 105-line chunk of code you'll find in KB article 302987.
This produces a form that you can use to load data from MapPoint and save it as a .ptm file with the Make Route Map button. Next, you'll use the Save as HTML button to invoke MapPoint and save the map in HTML format. Finally, you'll use the Close the Project button to close out your work. It's really pretty simple. If you're interested in learning more about working with MapPoint, please also check out KB article 302885 "HOWTO: Use the MapPoint 2002 Control and Automation with Visual Basic to Save a Map as HTML." It explains the code in the collection of subroutines that you'll grab from the Web page in Step 6 above.
Ed Tittel is a principal at LANWrights, Inc. a wholly-owned subsidiary of iLearning.com, where he writes and teaches on a variety of subjects, including markup languages, development tools, and IT certifications. Contact Ed via e-mail at firstname.lastname@example.org.