Example 1: MS Dev Studio C++ ATL
This example is an ATL application using the PTC Mathcad Prime API to exercise some fundamental methods and properties, and to demonstrate how to enable events. If you build this project, you must use BUILD and not REBUILD, as REBUILD removes the ptc.mathcadprime.automation.tlh and ptc.mathcadprime.automation.tli files from the RELEASE folder, so you will have to copy them back.
There are three main pieces of code:
• Main.cpp builds the user interface.
• MathcadPrimeComEvents2.cpp implements the methods of the MathcadPrimeComEvents2 class that tells PTC Mathcad Prime what to do on event.
• MathcadPrimeComClient.cpp implements callbacks for the ATL user interface.
The main routine instantiates a MathcadPrimeComClient, a generic class name for this example. During StarPrimeServer(), the callback creates a MathcadPrimeApplication3 and a MathcadPrimeComEvents2 object. These PTC Mathcad Prime objects are part of the API, and are the only two objects that you create with new.
1. Download the example here:
C++.NET.
2. To run the example, execute MathPrimeAutomation.exe. The C++ ATL Win32 application dialog window opens:
3. Click Start Mathcad Prime and wait until PTC Mathcad Prime opens.
4. Click Show Mathcad Prime to bring PTC Mathcad Prime to the foreground.
5. Click Hide Mathcad Prime to hide PTC Mathcad Prime.
6. Click Open Worksheet to browse to the worksheet that you want to open. Open the worksheet.
7. Click Open New Worksheet and ensure a new worksheet entitled Untitled-n.mcdx opens.
8. Click Close Worksheet and ensure that the last opened worksheet closes.
9. To check the events:
a. Click Enable Events.
b. Click the worksheet and type something. A message appears indicating a modified event occurred. Click OK to dismiss the message.
c. Click Save As. A message appears indicating a renamed event occurred. Click OK to dismiss the message.
d. Click Close Worksheet. A message appears indicating a close event occurred. Click OK to dismiss the message.
10. To close PTC Mathcad Prime, click Stop and Close Mathcad Prime.