Introduction
This is an AppWizard created using the MSVC's built-in Custom AppWizard. It is called GenWiz and it can be used with MSVC to create simple generic wizard skeletons. It is based on the CTreePropSheet class developed by Sven Wiegand.
This wizard is basically a clone of the MSVC's Custom AppWizard in terms of creating application skeletons by using templates and macros. The main reason to develop such a wizard was because I wanted the wizards to be independent executables instead of AWX executables, which can only be executed under the MSVC IDE.
Before creating this simple generic wizard, I searched on the Internet for information on how to access the AppWizard's functionality, implemented in MFCAPWZ.DLL. I found no info and therefore I came up with my version on how to parse the templates and replace macros.
An example of a wizard created with GenWiz can be found in this other article: PIC C Wizard.
How to Install
Download the zip file containing the source code and extract the GenWiz.AWX file, included under the \release folder, to your Program Files\Microsoft Visual Studio\Common\MSDev98\Template folder. Next time you start up the MSVC IDE, the genwiz AppWizard should be listed in the New Projects tab.
The Important "Stuff" Within GenWiz
There's a lot of reference material on the Internet and MSDN itself about how the AppWizard works, so I'll focus mainly in the set of functions that I coded to implement this wizard. These functions are those that are going to be part of any GenWiz's generated wizards:
CMapStringToString m_Dictionary;
BOOL CreateProjectFiles();
BOOL LoadProjectInfo();
void GetConfirmText( CString& sText );
void ProcessTemplates();
protected:
CString m_sTemplatesFolder;
CString m_sConfirmBuf;
CStringArray m_saTemplates;
CStringArray m_saTemplatesBuf;
void CreateAndFillMacros();
BOOL VerifyWizardConfigFile();
DWORD FileStatusInProject( CString& sFName );
PTCHAR LoadTemplate( LPCTSTR lpszTemplateName );
void AddMacroFromInt( LPCTSTR lpszMacro, int value );
void AddMacroFromDouble( LPCTSTR lpszMacro, double value );
static BOOL MyEnumResNameProc(
HANDLE hModule,
LPCTSTR lpszType,
LPTSTR lpszName,
LONG lParam
);
BOOL CreateDefaultTemplatesFromResources();
BOOL AskCreateDefaultTemplates();
void InitTemplatesFolder();
The next section shows how a wizard will create a skeleton, based on your provided templates:
void CWizDlg1::OnOK() {
if ( !pApp->LoadProjectInfo() ) {
CPropertyPage::OnCancel();
} pApp->ProcessTemplates();
CWizInfoDlg cdlg;
pApp->GetConfirmText( cdlg.m_sText );
int iRet = cdlg.DoModal();
if ( IDOK == iRet ) {
pApp->CreateProjectFiles();
CPropertyPage::OnOK();
}
else {
CPropertyPage::OnCancel();
}
}
The following code is found in the wizard's InitInstance()
:
InitTemplatesFolder();
if ( !VerifyWizardConfigFile() ) {
return FALSE;
}
m_pMainWnd = &wizardWnd;
int iRes = wizardWnd.DoModal();
if ( IDOK == iRes ) {}
else {}
Override these two functions: CPropertyPage::OnKillActive()
and CPropertyPage::OnSetActive()
in every property page in your wizard. Add code in OnSetActive()
to update the page's values from the WIZARDINFO
data structure. Add code in OnKillActive()
to enter the user's data into the WIZARDINFO
data structure. See example code in the wizard.
The Templates
- wizconfig.inf: this template is provided as an example on how the wizard could read information that goes directly into the
WIZARDINFO
structure.
- wizproj.inf: it contains the list of templates files that will be part of the generated project. For every template file that you add to the wizard, and if this file is needed in the generated project, you should add a line in this file.
- wizinfo.inf: contains text information that will be displayed just before your wizard is about to create a new project.
Remove the other three templates as they are provided as an example.
Adding New Templates
- Go to the resources section and select the "TEMPLATE" resource.
- Right-click and select Insert "TEMPLATE".
- A new TEMPLATE resource will be added and named as:
IDR_TEMPLATE1
. Change this name to something else, like the file name of the template, and make sure it is between quote marks, e.g.: "MYFILE.CPP". Also, change the location from res\ to template\.
Supported Directives
Your wizard will support the following directives that can be used in your templates:
$$IF
$$ENDIF
$$BEGINLOOP
$$ENDLOOP
$$
: Indicates a comment. It can only go at the beginning of a line and the whole line will be taken as comment.
Please check the MSDN documentation for more information on how to use these directives in your templates.
Notes:
The GenWiz will create a default skeleton having a CGridCtrl in the first dialog. It is just an example and it can be removed safely if not required in your wizard.
To add more dialogs or sub-sections to your wizard or modify the style of the property sheet, please refer to "Using CTreePropSheet" in this article.
History
05/14/2003: Initial release.