How to: Build and Run the ShapeAppMacroRecordingCSharp Sample

Visual Studio 2008

The ShapeAppMacroRecordingCSharp sample demonstrates how to integrate the Visual Studio Tools for Applications IDE with the ShapeAppCSharp sample host application to support macro recording. For more information, see ShapeApp Samples (Visual Studio Tools for Applications).

After you build and run ShapeAppMacroRecordingCSharp, you can load the application-level add-in that is included with the sample. To build and run ShapeAppMacroRecordingCSharp, perform the following steps:

  1. Install Visual Studio Tools for Applications.

  2. Extract the ShapeAppMacroRecordingCSharp sample.

  3. Open the ShapeAppMacroRecordingCSharp sample in Visual Studio and build it.

  4. Register ShapeAppMacroRecordingCSharp. This enables you to build and debug the sample add-in, and to use the project templates that are included with ShapeAppMacroRecordingCSharp to create your own add-ins.

  5. Build the sample add-in.

  6. Load the sample add-in into ShapeAppMacroRecordingCSharp. Record a macro and run it.

  7. (Optional) Unregister ShapeAppMacroRecordingCSharp. Doing this removes the registry entries that let you build and debug the sample add-in, and also removes the entries that let you use the project templates that are included with ShapeAppMacroRecordingCSharp.

To extract ShapeAppMacroRecordingCSharp

  1. Create a folder named ShapeAppSamples at the root of the Windows system drive (%SystemDrive%), and then create a subfolder named ShapeAppMacroRecordingCSharp. For example, if your system drive is C, the directory would be C:\ShapeAppSamples\ShapeAppMacroRecordingCSharp.

    NoteNote:

    Although you can extract ShapeAppMacroRecordingCSharp to any folder, the following procedures assume that you extract ShapeAppMacroRecordingCSharp to the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp folder.

  2. Open the Visual Studio Tools for Applications samples folder.

    By default, the samples folder is located at %ProgramFiles%\Visual Studio Tools For Applications 2.0 SDK\build number\Visual Studio Tools For Applications\Samples on 32-bit versions of Windows, or at %ProgramFiles(x86)%\Visual Studio Tools For Applications 2.0 SDK\build number\Visual Studio Tools For Applications\Samples on 64-bit versions of Windows.

  3. Right-click the ShapeAppMacroRecordingCSharp.zip file, and then click Extract All.

    NoteNote:

    This step assumes that your system is set to open .zip files using Compressed (zipped) Folders. If your system is set to open .zip files with another program, follow the instructions of that program to extract the contents of ShapeAppMacroRecordingCSharp.zip.

  4. Follow the instructions in the Extract Compressed (Zipped) Folders wizard to extract the contents of ShapeAppMacroRecordingCSharp.zip to the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp folder.

To build ShapeAppMacroRecordingCSharp

  1. Start Visual Studio 2008. If you are using Windows Vista as your operating system, start Visual Studio 2008 by using the Run as Administrator option.

  2. On the File menu, point to Open, and then click Project/Solution.

  3. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp folder.

  4. Select the ShapeAppMacroRecordingCSharp.sln file, and then click Open.

  5. On the Build menu, click Build Solution. Verify that the solution builds without errors.

To register ShapeAppMacroRecordingCSharp

  1. Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.

  2. Run the following command.

    cd "%SystemDrive%\ShapeAppSamples\ShapeAppMacroRecordingCSharp"
    
    NoteNote:

    If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that registers ShapeAppMacroRecordingCSharp can be run only in a 32-bit Command Prompt window.

  3. Type the following command to run the SetupShapeAppMacroRecordingCSharp.js script file. This script file registers ShapeAppMacroRecordingCSharp with Visual Studio Tools for Applications and configures the project templates so that they can be used from Visual Studio 2008.

    cscript SetupShapeAppMacroRecordingCSharp.js
    

    For more information about registering host applications, see Registering the Host Application.

    NoteNote:

    This command might require several minutes to complete.

    NoteNote:

    Each version of the ShapeAppCSharp sample provides a setup script. All setup scripts write to the same location in the registry. Therefore, you can only use the setup script to register one version of the ShapeAppCSharp sample application at a time.

To build the sample add-in

  1. On the File menu, point to Open, and then click Project/Solution.

  2. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp\sample AddIns\CSharp folder.

    NoteNote:

    The following instructions assume that you are building the Visual C# version of the add-ins. For Visual Basic versions of the add-ins, see the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp\sample AddIns\VisualBasic folder.

  3. Select the ShapeAppCSharpAddIns.sln file, and then click Open.

  4. On the Build menu, click Build Solution. Verify that the solution builds without errors.

    When you build the solution, the add-in assemblies are automatically copied as follows:

    For Windows XP and Windows Server 2003:

    • ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\My Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.

    For Windows Vista:

    • ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.

    ShapeAppMacroRecordingCSharp searches for add-ins in these directories.

  5. On the File menu, click Close Solution.

To load the sample add-in into ShapeAppMacroRecordingCSharp

  1. On the File menu of Visual Studio, point to Open, and then click Project/Solution.

  2. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppMacroRecordingCSharp folder.

  3. Select the ShapeAppMacroRecordingCSharp.sln file, and then click Open.

  4. Press F5.

  5. Verify that the message "Drawing Created" appears, and then click OK.

    This verifies that the add-in has loaded correctly.

  6. Verify that the message "Shape Location Changed" appears, and then click OK.

  7. Verify that the message "Shape Added to the drawing" appears, and then click OK.

    This demonstrates the use of event handlers in the add-in events defined in the host application.

  8. Verify that the message "Incorrect point values: X = -30, Y = -30" appears, and then click OK.

    This demonstrates the use of a custom exception.

  9. Verify that the message "ShapeApp Managed Sample with Macro Recording support" appears, and then click OK.

    This demonstrates the use of a static member in the object model.

To record a macro and run it

  1. On the Tools menu of ShapeAppMacroRecordingCSharp, click Record Macro.

  2. Drag a triangle onto an open document.

    The message "Shape Added to the drawing" appears.

  3. Click OK to close the message box.

  4. On the Tools menu, click Stop Macro Recording.

    ShapeApp saves a new project that contains macro code in one of the following two directories:

    For Windows XP and Windows Server 2003:

    • %UserProfile%\My Documents\ShapeAppCSharp\Macros

    For Windows Vista:

    • %UserProfile%\Documents\ShapeAppCSharp\Macros

    If you record any additional macros, ShapeAppMacroRecordingCSharp will add the macro code to this project.

  5. In ShapeAppMacroRecordingCSharp, right-click an empty part of the document, and then click Clear.

  6. On the Tools menu, click Run Macro.

  7. Click Macro1, and then click Run.

    Verify that a triangle is added to the document.

  8. In the MacroManager dialog box, click OK.

  9. Exit ShapeAppMacroRecordingCSharp.

To unregister ShapeAppBasicCSharp

  1. Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.

  2. Run the following command.

    cd "%SystemDrive%\ShapeAppSamples\ShapeAppMacroRecordingCSharp"
    
    NoteNote:

    If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that unregisters ShapeAppMacroRecordingCSharp can be run only in a 32-bit Command Prompt window.

  3. Type the following command to run the RemoveShapeAppCSharp.js script file. This script file removes registry entries that let you to build and debug the sample add-in, and also removes entries that let you use the project templates that are included with ShapeAppMacroRecordingCSharp to create your own add-ins.

    cscript RemoveShapeAppCSharp.js
    
    NoteNote:

    This command might require several minutes to complete.

Community Additions

ADD
Show: