Extending the MapPoint ActiveX Control - Pt. II
Sergiy Pavlov continues his exploration on how to unleash the full functionality of MapPoint in the ActiveX control
Part Two of Two
1. Introduction to Part II
In Part I of this article we made the LocationSensor command functionality programmatically accessible for MapPoint 2002 ActiveX control users. We introduced clsMapPoint class and hWnd_Frame property to dynamically locate
a window handle of the internal ActiveX control’s window (named ‘ActiveX frame window’) of the
MapPoint application’s main frame window. We could then mimic the LocationSensor user interface (menu) event by
posting WM_COMMAND message # 35331 to a window captured by hWnd_Frame. The same technique could be similarily used
with a number of other MapPoint menu commands. The only implementation difference between them would be WM_COMMAND
message’s value, for example:
Menu Tools -> MeasureDistance: # 58224
Menu File -> SaveAs: # 57604
Menu File -> ExportToPocketStreets: # 35334
Menu File -> Print: # 55955
However, Menu File -> SaveAsWebPage (#35032) command message had no effect whatsoever. Frankly, I sorted out all the internal ActiveX control windows as possible command message targets and was already thinking giving up, when something unexpected in the Microsoft Spy++ Windows View caught my eye.
2. An alternative MapPoint window
Download and expand Test VB project - Part2. If you have the European version of MapPoint, set conditional compilation
argument EURO to 1 in Project properties ->make
Run the Microsoft Spy++ utility together with the Test VB application (note, that this time we run the test alone,
without the MapPoint application). In the Spy++ Windows View you can now find a top-level node corresponding to
‘MapPoint’ application (Fig.2 in Part I of this article) as well as a stand-alone node “Map - Microsoft MapPoint
North America” (Fig.6) reminding us the MapPoint application’s main frame window (Fig.1 in Part I of this article):

Figure 6
There is a difference in how complex the structure of the window objects contained by the top-level “Map- Microsoft MapPoint North America” window: this time there is only one child object under the node’s hierarchy. We can make an assumption that the MapPoint application’s main frame window does always exist, even if invisible and empty, - no matter how you are running MapPoint: the application itself or the control-based custom aplication. So the next step will be testing that hidden window on response to SaveAsWebPage (#35032) command message. To find the MapPoint main frame window dynamically use hWnd_EXE property of the extension class:
To activate SaveAsWebPage programmatically, we will post WM_COMMAND message # 35032 to a window captured by hWnd_EXE property:
The test VB application executes that code by choosing File -> TEST SaveAsWebPage... Test application menu command. Doing that makes the ‘Save as web page’ dialog appear. Check whether it functions correctly. It does, except that the dialog is not modal as it should be (you can click on the main application window).
3. Simulate modal window using Win API
To simulate the ‘modal’ behaviour, follow these steps after activating ‘Save as web page’ dialog:
1. Disable the application’s main form
2. Make the dialog window topmost (use WinAPI)
3. Wait until the dialog window is closed by user (use WinAPI to detect it)
4. Enable the application’s main form
5. Resume processing
Function WaitForDialogWnd below implements the described algorithm. The parameter sWndTitle is the dialog’s window title, so we may reuse the code to emulate modal behaviour for different dialog windows, if needed:
Test now the ‘Save as web page’ dialog behaviour by choosing File -> Save As Web Page... Test application menu command.
4. Putting it all together
Now, as we have number of MapPoint menu commands implemented through different API calls, it makes sense to group them by the parent menu (File, Edit, etc.) and create a common method SendCommand with a Select Case statement in it to dispatch a command to the specific routine. That simplifies the class clsMapPoint interface and makes its use straightforward, like in the example below:
I leave it to the reader’s consideration which functionality does indeed require the WinAPI –based technique, or
can be better implemented using existing ActiveX interface. In the test application I tried to implement the complete
set of MapPoint menu commands (at least as complete as I could) using only the technique of interest. I would,
however, like to point out that the proposed algorithm and the implementation code might require further fine-tuning as well as de-bugging. Also, it could become fully or partially obsolete (simply stop working) in the future versions of the MapPoint
software.
Discuss this story in the forum.
Author: Sergiy Pavlov Email: baal_2000(AT)yahoo.com Sergiy Pavlov is a GIS/GPS/Tracking Solutions Developer for GEOTAB North America in Burlington, ON. Professional interests range from software and algorithms development to electrical engineering.
|