home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / customwz / sampleaw.cpp < prev    next >
C/C++ Source or Header  |  1998-03-05  |  5KB  |  155 lines

  1. // sampleaw.cpp: implementation of CSampleAppWiz class.
  2. //
  3. // Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include "customwz.h"
  8. #include "sampleaw.h"
  9. #include "chooser.h"
  10. #include "zap.h"
  11. #include "options.h"
  12.  
  13. #ifdef _PSEUDO_DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // The CSampleAppWiz class.  Here we override many member functions of
  20. //  CCustomAppWiz.
  21.  
  22. // Initialize state of this custom AppWizard.
  23. void CSampleAppWiz::InitCustomAppWiz()
  24. {
  25.     m_pChooser = new CDialogChooser;
  26.     m_bOverrideProcessing = FALSE;
  27.     SetNumberOfSteps(2);                    // Initially two steps
  28.     // Set the macro corresponding to the Custom AppWizard target type.
  29.     //  This is used in mfcapwz.dll when it creates the target.
  30.     DefineBoolMacro(_T("PROJTYPE_CUSTOMAW"), TRUE);
  31. }
  32.  
  33. // Before exiting, deallocate memory used for the dialog chooser
  34. void CSampleAppWiz::ExitCustomAppWiz()
  35. {
  36.     ASSERT(m_pChooser != NULL);
  37.     delete m_pChooser;
  38.     m_pChooser = NULL;
  39. }
  40.  
  41. // This custom AppWizard only targets Win32 platform, so don't display
  42. //  any others.
  43. void CSampleAppWiz::GetPlatforms(CStringList& Platforms)
  44. {
  45.     POSITION pos = Platforms.GetHeadPosition();
  46.     while (pos != NULL)
  47.     {
  48.         POSITION posCurr = pos;
  49.         CString strPlatform = Platforms.GetNext(pos);
  50.         if (strPlatform.Left(5) != _T("Win32"))
  51.             Platforms.RemoveAt(posCurr);
  52.     }
  53. }
  54.  
  55. // Set options & macros derived from project name entered by end-user.
  56. void SetRootOptions()
  57. {
  58.     // Set "FILEBASE" macro
  59.     CString strFileBase;
  60.     sampleaw.m_Dictionary.Lookup(_T("Root"), strFileBase);
  61.     DefineStringMacro(_T("filebase"), strFileBase);
  62. }
  63.  
  64. // If the end-user clicks next, let the dialog chooser decide
  65. //  what to pop up next.
  66. CAppWizStepDlg* CSampleAppWiz::Next(CAppWizStepDlg* pDlg)
  67. {
  68.     // If the end-user is dismissing the New Project dialog,
  69.     //  call DefineRootMacros
  70.     if (pDlg == NULL)
  71.         SetRootOptions();
  72.  
  73.     return m_pChooser->Next(pDlg);
  74. }
  75.  
  76. // If the end-user clicks back, let the dialog chooser decide
  77. //  what to pop up.
  78. CAppWizStepDlg* CSampleAppWiz::Back(CAppWizStepDlg* pDlg)
  79. {
  80.     return m_pChooser->Back(pDlg);
  81. }
  82.  
  83. // We override LoadTemplate as part of implementing the project
  84. //  zapper.
  85. LPCTSTR CSampleAppWiz::LoadTemplate(LPCTSTR lpszTemplateName,
  86.         DWORD& rdwSize, HINSTANCE hInstance)
  87. {
  88.     // If the resource we're loading contains a backslash in it...
  89.     if (_tcschr(lpszTemplateName, _T('\\')))
  90.     {
  91.         // ... then it's a file we're about to zap (see CZap).
  92.         m_bOverrideProcessing = TRUE;               // Remember we're overriding parsing
  93.         return m_Zap.LoadFile(lpszTemplateName, rdwSize);// Prepare the zapper for this file
  94.     }
  95.  
  96.     // Otherwise, defer to the base class implementation of LoadTemplate
  97.     m_bOverrideProcessing = FALSE;
  98.  
  99.     // But first, be sure to define GENERATED_NEWPROJ_INF_FILES if it's time
  100.     if (!_tcsicmp(lpszTemplateName, _T("newnwprj.inf")))
  101.         m_Zap.DefineGeneratedNewprojInfMacro();
  102.  
  103.     return CCustomAppWiz::LoadTemplate(lpszTemplateName, rdwSize, hInstance);
  104. }
  105.  
  106. // We override ProcessTemplate as part of implementing the project
  107. //  zapper.
  108. void CSampleAppWiz::ProcessTemplate(LPCTSTR lpszInput, DWORD dwSize, OutputStream* pOutput)
  109. {
  110.     // If we set m_bOverrideProcessing in LoadTemplate, then we're about
  111.     //  zap this file.
  112.     if (m_bOverrideProcessing)
  113.     {
  114.         // Zap the file into a template
  115.         m_Zap.ZapFile(lpszInput, dwSize, pOutput);
  116.         return;
  117.     }
  118.  
  119.     // We're not zapping this file, so defer to the base class
  120.     //  implementation of ProcessTemplate
  121.     CCustomAppWiz::ProcessTemplate(lpszInput, dwSize, pOutput);
  122. }
  123.  
  124. // We override PostProcessTemplate as part of implementing the project
  125. //  zapper.
  126. void CSampleAppWiz::PostProcessTemplate(LPCTSTR szTemplate)
  127. {
  128.     // If we set m_bOverrideProcessing in LoadTemplate, then we've just
  129.     //  zapped this file.  Unload it.
  130.     if (m_bOverrideProcessing)
  131.     {
  132.         m_Zap.UnloadFile();
  133.         m_bOverrideProcessing = FALSE;
  134.     }
  135. }
  136.  
  137. // The dialog chooser keeps track of which type of custom AppWizard we're
  138. //  creating (based on project, based on appwiz sequence, or base) so it
  139. //  knows what dialog to pop up next.  Any request to set or get the
  140. //  custom AppWizard type goes through the chooser.
  141.  
  142. void CSampleAppWiz::SetCustomType(int nCustomType)
  143. {
  144.     m_pChooser->SetCustomType(nCustomType);
  145. }
  146.  
  147. int CSampleAppWiz::GetCustomType()
  148. {
  149.     return m_pChooser->GetCustomType();
  150. }
  151.  
  152.  
  153. // Create one global instance of this class anyone can see.
  154. CSampleAppWiz sampleaw;
  155.