Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Article

Custom Wizard for OpenGL in Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
4.20/5 (2 votes)
2 Feb 20074 min read 78.1K   2.4K   36   10
Create OpenGL Window using MFC in Visual Studio .NET

Sample Image - wizard.gif

Introduction

This Article explains about custom wizard making and OpenGL custom wizard in Visual Studio .NET 2003 using MFC custom wizard. Many people have a question to custom wizard in Visual Studio .NET. The reason of this issue is chaged by a formula from Dialog coding method to HTML define method. This article explains about "How to make Custom Wizard in Visual .NET Enviroment?"

Compare Custom Wizard between Visual Studio 6.0 and Visual Studio .NET

Untile Visual Studio 6.0, we made custom wizard using dialog resource. and we define properties and conditions using resource control.

Sample screenshot

This picture shows about resource editing process in Visual Studio 6. But Visual Studio .NET IDE (integrated development enviroment) do not no more support dialog resource editing process for custom wizard. In this time, VS.NET 2003 or VS.NET 2005 IDE enviroment use HTML editing enviromet instead of dialog editing enviroment.

Sample screenshot

Overview of Visual C++ Custom Wizard

It explains the most common features of a custom wizard. A typical project wizard template contains the files listed below:

[name].vsz

Identifies the wizard engine and provides context and optional custom parameters.

VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.7.1

Param="WIZARD_NAME = OpenGL Wizard"
Param="FALLBACK_LCID = 1033"
Param="SOURCE_FILTER = cpp;.. and other options"
Param="HEADER_FILTER = h; .. and other options"
Param="RESOURCE_FILTER = rc; .. and other options"

[name].vsdir

This file provides a routing service between the Visual Studio shell and the items in the wizard project.

OpenGL Wizard.vsz| |OpenGL Wizard|1|OpenGL MFC Application| |6777| |OpenGL Wizard

Templates.inf

Templates.inf is a text file that contains a list of templates to use for the project. Note that the Template.inf is a template file itself (you can use directives to indicate which files to include in the project).

default.vcproj

Xml file contains project type information.

<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject ProjectType="Visual C++" Version="7.10">
 <Platforms>
  <Platform
   Name="Win32"/>
 </Platforms>
 <Configurations>
  <Configuration Name="Debug|Win32"></Configuration>
  <Configuration Name="Release|Win32"></Configuration>
 </Configurations>
</VisualStudioProject>

"Template file" folder

This folder contains files that will be included in the project. Note that the location on hard drive is "$(ProjectDir)\Template Files\1033".

readme.txt
sample.txt
stdafx.h
stdafx.cpp
OpenGLView.h
OpenGLView.cpp
OpenGLDoc.h
OpenGLDoc.cpp
OpenGL.h
OpenGL.cpp
MainFrm.h
MainFrm.cpp
OpenGL.rc
Res/OpenGL.ico
Res/OpenGL.rc2
Res/OpenGLDoc.ico
Res/Toolbar.bmp
Res/OpenGL.manifest
Resource.h
earth.bmp

"HTML files" folder

Contains the HTML file (user interface) used by the wizard, one file per page wizard. The first file is "Default.htm". Location on hard drive is "$(ProjectDir)\Html\1033".

"Script Files" folder

The Custom Wizard creates a JScript file called "Default.js" for each project.
It also includes "Common.js". These files contain JScript functions that give you access to the Visual C++ object models to customize a wizard.

function OnFinish(selProj, selObj) { ... etc }
function CreateCustomProject(strProjectName, strProjectPath) { ... etc }
function CreateCustomProject(strProjectName, strProjectPath) { ... etc }

function AddFilters(proj) { ... ect }
function AddConfig(proj, strProjectName) { ... etc }
function DelFile(fso, strWizTempFile) { ... etc }

function CreateCustomInfFile() { ... etc }

function GetTargetName(strName, strProjectName) { ... etc }

function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) { ... etc }

How to make Project Project Struct

Sample screenshot

For this article, I have chosen to create a MFC Application project for creating C project. My requisites are:

  1. Precompiled source Files : "stdafx.cpp", "stdafx.h"
    1. Define OpenGL Header Files
  2. Application source files : "OpenGL.cpp","OpenGL.h"
  3. MainFrame source Files : "MainFrm.cpp","MainFrm.h"
  4. Document source Files : "OpenGLDoc.cpp","OpenGLDoc.h"
  5. View source Files : "OpenGLView.cpp","OpenGLView.h"
  6. Resource Files : "OpenGL.rc","res/OpenGL.ico","res/OpenGLDoc.ico","res/Toolbar.bmp","res/OpenGL.rc2","OpeGL.manifest","Earth.bmp"
  7. File -> New -> Project : Custom Wizard chose
  8. Add Project Name
  9. Add Project Location

Editing HTML

Sample screenshot

This picture shows about editing html screenshot. I create HTML resource from ToolBox. And I defined a HTML resource ID. It use a condition for source files to template files.

For example :

If i define a SUPPORT_FOG_SUPPORT in html. it set the condition of source code. it use this like to source files. [!if id_value] some source code [!endif]

void C[!output PROJECT_NAME]View::InitOpenGL(void) // output project class
{
[!if SUPPORT_ALPHA_BLEND]
 glEnable(GL_DEPTH_TEST);                                      // depth buffering(z-buffering) 가동
[!endif]

 glEnable(GL_NORMALIZE);                                       // unit vector change
 glEnable(GL_COLOR_MATERIAL);

 Obj=gluNewQuadric();

[!if SUPPORT_OMNI_LIGHT || SUPPORT_SPOT_LIGHT]
 InitLight();
[!endif]

[!if SUPPORT_TEXTURE_EFFECT]
 InitTexture();
[!endif]

[!if SUPPORT_ALPHA_BLEND]
 InitAlphaTest();
[!endif]
<blink>[!if SUPPORT_FOG_EFFECT]</blink>
 InitFog();
[!endif]
[!if NOSUPPORT_FOG_EFFECT]
 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
[!endif]
 InitShadingModel();

 glMatrixMode(GL_PROJECTION);                                  // initialize projection matrix
 glLoadIdentity();

 InitProjection();

 glMatrixMode(GL_MODELVIEW);                                   // initialize modelview matrix
 glLoadIdentity();
}

How to make scripts

Script file decide important key in making Project Project Path, Project Name, Project options and File.

OnFinish function makes Project Name and Project Path using Input parameter at Project Wizard.

function OnFinish(selProj, selObj)
    {
     try
     {
      var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
      var strProjectName = wizard.FindSymbol('PROJECT_NAME'); 
      selProj = CreateCustomProject(strProjectName, strProjectPath);
      AddConfig(selProj, strProjectName);
      AddFilters(selProj); 
      var InfFile = CreateCustomInfFile();
      AddFilesToCustomProj(selProj, strProjectName, strProjectPath, InfFile);
      PchSettings(selProj);
      InfFile.Delete(); 
      selProj.Object.Save();
     }
     catch(e)
     {
      if (e.description.length != 0)
       SetErrorInfo(e);
      return e.number
     }
    } 

CreateCustomProject function makes Custom Project Wizard using default.vcproj and wizard type.

function CreateCustomProject(strProjectName, strProjectPath)
    {
     try
     {
      var strProjTemplatePath = wizard.FindSymbol('PROJECT_TEMPLATE_PATH');
      var strProjTemplate = '';
      strProjTemplate = strProjTemplatePath + '\\default.vcproj'; 
      var Solution = dte.Solution;
      var strSolutionName = "";
      if (wizard.FindSymbol("CLOSE_SOLUTION"))
      {
       Solution.Close();
       strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME");
       if (strSolutionName.length)
       {
        var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length);
        Solution.Create(strSolutionPath, strSolutionName);
       }
      } 
      var strProjectNameWithExt = '';
      strProjectNameWithExt = strProjectName + '.vcproj'; 
      var oTarget = wizard.FindSymbol("TARGET");
      var prj;
      if (wizard.FindSymbol("WIZARD_TYPE") == vsWizardAddSubProject)  // vsWizardAddSubProject
      {
       var prjItem = oTarget.AddFromTemplate(strProjTemplate, strProjectNameWithExt);
       prj = prjItem.SubProject;
      }
      else
      {
       prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt);
      }
      return prj;
     }
     catch(e)
     {
      throw e;
     }
    } 
AddFilter function filtering each type from template files.
function AddFilters(proj)
{
 try
 {
  // Add the folders to your project using Templates.inf
  var strSrcFilter1 = wizard.FindSymbol('SOURCE_FILTER');
  var strSrcFilter2 = wizard.FindSymbol('HEADER_FILTER');
  var strSrcFilter3 = wizard.FindSymbol('RESOURCE_FILTER');

  var group1 = proj.Object.AddFilter('Source Files');  // Source Files Group create
  var group2 = proj.Object.AddFilter('Header Files');  // Header Files Group create
  var group3 = proj.Object.AddFilter('Resource Files');   // Resource files Group create


  // Apply Filter
  group1.Filter = strSrcFilter1;
  group2.Filter = strSrcFilter2;
  group3.Filter = strSrcFilter3;
 }
 catch(e)
 {
  throw e;
 }
}

This time is AddConfig function. This function is very important for project properties. This function decide compile type. The Object get configurations in compile type like Debug and Release. And config variance insert options when project propertile like charset, library type , using mfc library. The CLTool variance is "Compile options" variance. This variance decide compile options like debugenabled, multi thread, compile level, precompiled header and preprocess options. The LinkTool variance is "Link options" variance. This variance decide link
options like database file, additional library.

function AddConfig(proj, strProjectName)
{
 try
 {
  var config = proj.Object.Configurations('Debug');
  config.IntermediateDirectory = 'Debug';
  config.OutputDirectory = 'Debug';
  config.CharacterSet = charSetMBCS;
  config.useOfMfc = useOfMfc.useMfcDynamic;
  var CLTool = config.Tools('VCCLCompilerTool');
  // TODO: Add compiler settings
  CLTool.DebugInformationFormat = debugEnabled;
  CLTool.DebugInformationFormat = debugOption.debugEditAndContinue;
  CLTool.SuppressStartupBanner = true;
  CLTool.RuntimeLibrary = runtimeLibraryOption.rtMultiThreadedDebugDLL;
  CLTool.WarningLevel = warningLevelOption.warningLevel_3;
  CLTool.Optimization = optimizeOption.optimizeDisabled;
  CLTool.MinimalRebuild = true;
  CLTool.DebugInformationFormat = debugOption.debugEditAndContinue;
  CLTool.PreprocessorDefinitions = "WIN32;_WINDOWS;_DEBUG";
  CLTool.UsePrecompiledHeader = pchGenerateAuto;
  var LinkTool = config.Tools('VCLinkerTool');
  // TODO: Add linker settings
  LinkTool.ProgramDatabaseFile = "$(OutDir)/$(ProjectName).pdb";
  LinkTool.GenerateDebugInformation = true;
  LinkTool.LinkIncremental = linkIncrementalYes;
  LinkTool.OutputFile = "$(OutDir)/$(ProjectName).exe";
  LinkTool.SuppressStartupBanner=true;  // nologo
  LinkTool.AdditionalDependencies="opengl32.lib glu32.lib glut32.lib";
  LinkTool.SubSystem = subSystemOption.subSystemWindows;

  config = proj.Object.Configurations('Release');
  config.IntermediateDirectory = 'Release';
  config.OutputDirectory = 'Release';
  config.CharacterSet = charSetMBCS;
  config.useOfMfc = useOfMfc.useMfcDynamic;

  var CLTool = config.Tools('VCCLCompilerTool');
  // TODO: Add compiler settings
  CLTool.DebugInformationFormat = debugEnabled;
  CLTool.DebugInformationFormat = debugOption.debugEnabled;
  CLTool.SuppressStartupBanner = true;
  CLTool.RuntimeLibrary = runtimeLibraryOption.rtMultiThreadedDLL;
  CLTool.WarningLevel = warningLevelOption.warningLevel_3;
  CLTool.Optimization = optimizeOption.optimizeMaximizeSpeed;
  CLTool.MinimalRebuild = true;
  CLTool.PreprocessorDefinitions = "WIN32;_WINDOWS;NDEBUG";
  CLTool.UsePrecompiledHeader = pchGenerateAuto;
  var LinkTool = config.Tools('VCLinkerTool');
  // TODO: Add linker settings
  LinkTool.ProgramDatabaseFile = "$(OutDir)/$(ProjectName).pdb";
  LinkTool.GenerateDebugInformation = true;
  LinkTool.LinkIncremental = linkIncrementalYes;
  LinkTool.OutputFile = "$(OutDir)/$(ProjectName).exe";
  LinkTool.SuppressStartupBanner=true;  // nologo
  LinkTool.AdditionalDependencies="opengl32.lib glu32.lib glut32.lib";
  LinkTool.SubSystem = subSystemOption.subSystemWindows;
 }
 catch(e)
 {
  throw e;
 }
}

Finally, I modified GetTargetName function. This Function make target project files usng project name. First i get a project name from project wizard. And this function chaging from template files to target files.

function GetTargetName(strName, strProjectName)
{
 try
 {
  // TODO: set the name of the rendered file based on the template filename
  var strTarget = strName;
  var strProjectName = wizard.FindSymbol('PROJECT_NAME');

  if (strName == 'readme.txt')
   strTarget = 'ReadMe.txt';

  if (strName == 'sample.txt')
   strTarget = 'Sample.txt';

  if (strName == 'stdafx.cpp')
   strTarget =  'stdafx.cpp';

  if (strName == 'stdafx.h')
   strTarget =  'stdafx.h';

  if (strName == 'OpenGL.h')
   strTarget =  strProjectName + '.h';

  if (strName == 'OpenGL.cpp')
   strTarget =  strProjectName + '.cpp';

  if (strName == 'MainFrm.h')
   strTarget =  'MainFrm.h';

  if (strName == 'MainFrm.cpp')
   strTarget =  'MainFrm.cpp';

  if (strName == 'OpenGLView.h')
   strTarget =  strProjectName + 'View.h';

  if (strName == 'OpenGLView.cpp')
   strTarget =  strProjectName + 'View.cpp';

  if (strName == 'OpenGLDoc.h')
   strTarget =  strProjectName + 'Doc.h';

  if (strName == 'OpenGLDoc.cpp')
   strTarget =  strProjectName + 'Doc.cpp';

  if (strName == 'OpenGL.rc')
   strTarget =  strProjectName + '.rc';

  if (strName == 'resource.h')
   strTarget =  'Resource.h';

  if (strName == 'Res/OpenGL.ico')
   strTarget =  'Res/' + strProjectName + '.ico';

  if (strName == 'earth.bmp')
   strTarget =  'earth.bmp';

  if (strName == 'Res/OpenGL.rc2')
   strTarget =  'Res/' + strProjectName + '.rc2';

  if (strName == 'Res/OpenGLDoc.ico')
   strTarget =  'Res/' + strProjectName + 'Doc.ico';

  if (strName == 'Res/OpenGL.manifest')
   strTarget =  'Res/' + strProjectName + '.manifest';

  return strTarget;
 }
 catch(e)
 {
  throw e;
 }
}

Installation Guide

You extract demo zip file. It makes Visual Studio .NET 2003 folder. This folder compose like this :

vc 7-> vcprojects

             -> OpenGL Wizard.ico : icon file

             -> OpenGL Wizard.vsz : Project Wizard connection file

      -> VCWizards

             ->  OpenGL Wizard

                   -> 1033 : html style css file

                   -> HTML : html files

                   -> Images : wizard image fles

                   -> Scripts : script for wizard

                   -> Templates : project template source files for creating project
And you copy to Visual Studio .NET folder. If you copy this files, you shown the OpenGL Wizard on the New Project Create Wizard. The OpenGL Wizard compose nine steps. First step is Document type. It is descript this Program. The other options is associate with OpenGL library like Light, Projection, Shading, Alpha Blend, Fog, Texture, Animation, Picking.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Korea (Republic of) Korea (Republic of)
I hope to help your coding processing.

Comments and Discussions

 
QuestionLanguage Pin
Sharjith6-Oct-07 6:35
professionalSharjith6-Oct-07 6:35 
AnswerRe: Language Pin
Youngho Kim14-Nov-07 23:37
Youngho Kim14-Nov-07 23:37 
QuestionHow to use it in Visual Studio 2005 Pin
yakumo082929-Jan-07 22:13
yakumo082929-Jan-07 22:13 
AnswerRe: How to use it in Visual Studio 2005 Pin
Youngho Kim2-Feb-07 14:27
Youngho Kim2-Feb-07 14:27 
AnswerRe: How to use it in Visual Studio 2005 Pin
Youngho Kim8-Feb-07 21:03
Youngho Kim8-Feb-07 21:03 
GeneralThe file is missing !! Pin
cjvtnt21-Dec-06 6:24
cjvtnt21-Dec-06 6:24 
GeneralRe: The file is missing !! Pin
Tim Craig21-Dec-06 8:57
Tim Craig21-Dec-06 8:57 
AnswerRe: The file is missing !! Pin
Youngho Kim21-Dec-06 14:20
Youngho Kim21-Dec-06 14:20 
GeneralI can't download files Pin
crac21-Dec-06 0:46
crac21-Dec-06 0:46 
GeneralRe: I can't download files Pin
Tim Craig21-Dec-06 8:57
Tim Craig21-Dec-06 8:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.