Create a Visual C++ Wizard for Visual Studio 2005

If you often create VC++ projects that are very similar, such as DLLs that follow some guidelines or rules for common integration in an application (like a plug-in based application), you might get tired of creating a default VC++ project and then doing the same changes to it over and over again. In that case, perhaps it’s time for you to write a VC++ wizard that automatically generates all that you need to start doing work.

In this article, I’ll show you how to create a simple wizard for a Win32 console-based application. This project template will have several particularities:

  • Uses precompiled headers, so stdafx.h and stdafx.cpp will be generated
  • Contains files for a dummy class that the user chooses to name; the name of the files will be the same as the class. These files will be placed inside a subfolder called ‘src’ that will be added to the Additional Include Directories property
  • Includes comments at the beginning of each file containing the author and the date of creation
  • Includes a file called main.cpp containing the main() function that will instantiate an object of the created class
  • In addition, a readme.txt text file should be generated, but not added to the list of project files

Creating the Project

To create a new wizard project, go to File > New > Project and select Visual C++, and then from the list of available templates customwiz. Let’s call this project “DummyWin32Wizard”, because after all, that’s exactly what it is. You will be asked to select the settings for this project. First, put “DummyWin32Wizard” in the “Wizard Friendly Name” edit, check the “User Interface” checkbox, and set the number of pages of the wizard to 1, because that’s all what we’ll need.

When the project is created, it will have several created files that you can see in the following picture. The most important ones are described here:

  • Default.html: The file containing the HTML code for the wizard’s interface pages
  • Default.js: The file containing the JScript code called by the framework when the wizard is run
  • Default.vcproj is a VC++ project file containing the minimum information for a project, such as project type, platforms, and list of configurations
  • DummyWin32Wizard.ico: The icon associated with the template in the list of VisualC++ templates
  • DummyWin32Wizard.vsz: The start point of the wizard. Itcontains information about the wizard project, such as name, path (either absolute or relative), or LCID. This file basically names a COM component that Visual Studio can use to create an item, and lists the parameters the component receives. You can read more about the file in MSDN. Default content of the file is:
    VSWIZARD 7.0
    Wizard=VsWizard.VsWizardEngine.8.0
    
    Param="WIZARD_NAME = DummyWin32Wizard"
    Param="ABSOLUTE_PATH = D:\Cilu\VC++\codeguru\articles\
                           wizard\DummyWin32Wizard"
    Param="FALLBACK_LCID = 1033"
    
  • DummyWin32Wizard.vsdir: lists all the items and their properties that are displayed in the selection dialog and the corresponding .vsz file; the default content of the file is listed below:
    DummyWin32Wizard.vsz| |DummyWin32Wizard|1|
       TODO: Wizard Description.| |6777| |DummyWin32Wizard
    

    The information listed in this file is:

    • DummyWin32Wizard.vsz: The relative path to the .vsz file
    • Optional GUID: A component that contains resources (not specified in the about string)
    • DummyWin32Wizard: The name of the template displayed in the list of available templates
    • 1: The sort priority for displaying the items in the list of available templates; items with lower numbers are displayed at the beginning of the list
    • TODO: Wizard Description: A string describing the wizard, shown in the status field
    • Optional GUID or path of a DLL: Contains the icon to be with the item in the list (not specified in the about string)
    • 6777: The resource ID of the icon in the component
    • Optional additional flags (not specified in the about string)
    • DummyWin32Wizard: The suggested base name for the item. A number is inserted before the extension of the item, if one exists. If DummyWin32Wizard is replaced, for instance, with <DummyWin32Wizard>, the wizard will not suggest any name and the user is forced to enter a name for the item

When you create the custom wizard project, Visual Studio automatically copies the files DummyWin32Wizard.ico, DummyWin32Wizard.vsd, and DummyWin32Wizard.vsdir in the folder VC\vcprojects of the Visual Studio 8 installation folder. That means that if you go to File > New > Project and select VisualC++ you’ll already be able to create a project with it.

I would suggest changing the content of the DummyWin32Wizard.vsdir file to

DummyWin32Wizard.vsz| |Dummy Win32 Wizard|1|Just a training
   purpose wizard| |6777| |<DummyWin32Wizard>

and copying it to the VC\vcprojects folder, so that the templates dialog shows what you want.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read