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

  1. // typedlg.cpp : implementation file
  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 "typedlg.h"
  10. #include "options.h"
  11. #include "paint.h"
  12.  
  13. #ifdef _PSEUDO_DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18.  
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CCustomTypeDlg dialog
  22.  
  23.  
  24. CCustomTypeDlg::CCustomTypeDlg()
  25.     : CAppWizStepDlg(CCustomTypeDlg::IDD)
  26. {
  27.     //{{AFX_DATA_INIT(CCustomTypeDlg)
  28.     m_nCustomType = CUSTOMTYPE_ZAP;
  29.     m_nCustomSteps = 1;
  30.     m_strTitle = _T("");
  31.     //}}AFX_DATA_INIT
  32.     m_strLastCustomSteps = _T("1");
  33.     SetBitmap();
  34. }
  35.  
  36.  
  37. void CCustomTypeDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39.     CAppWizStepDlg::DoDataExchange(pDX);
  40.     //{{AFX_DATA_MAP(CCustomTypeDlg)
  41.     DDX_Radio(pDX, IDC_ZAP, m_nCustomType);
  42.     DDX_Text(pDX, IDC_STEPS, m_nCustomSteps);
  43.     DDV_MinMaxUInt(pDX, m_nCustomSteps, 0, 9);
  44.     DDX_Text(pDX, IDC_TITLE, m_strTitle);
  45.     //}}AFX_DATA_MAP
  46.     EnableCustomSteps();
  47. }
  48.  
  49. // Base default title of custom AppWizard off of project name.  This is called
  50. //  by CDialogChooser when the New Project dialog is dimissed with a
  51. //  new project name.
  52. void CCustomTypeDlg::UpdateTitle(const CString& strRoot)
  53. {
  54.     m_strTitle = strRoot + _T(" AppWizard");
  55. }
  56.  
  57. BEGIN_MESSAGE_MAP(CCustomTypeDlg, CAppWizStepDlg)
  58.     //{{AFX_MSG_MAP(CCustomTypeDlg)
  59.     ON_COMMAND_EX(IDC_ZAP, OnClickedRadio)
  60.     ON_COMMAND_EX(IDC_SEQUENCE, OnClickedRadio)
  61.     ON_COMMAND_EX(IDC_CUSTOM, OnClickedRadio)
  62.     ON_WM_PAINT()
  63.     //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65.  
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CCustomTypeDlg message handlers
  69.  
  70. #define STEP1_LEFT          8
  71. #define STEP1_TOP           40
  72. #define STEP1_WIDTH         179
  73. #define STEP1_HEIGHT        180
  74.  
  75. // Override OnPaint to draw pictures on the left side
  76. void CCustomTypeDlg::OnPaint()
  77. {
  78.     CPaintDC dc(this); // device context for painting
  79.  
  80.     PaintBackground(&dc, this);
  81.  
  82.     CDC dcMem;
  83.     if (!dcMem.CreateCompatibleDC(&dc))
  84.         return;
  85.  
  86.     // Picture
  87.     PaintBitmap(m_nBitmap, STEP1_LEFT, STEP1_TOP, STEP1_WIDTH, STEP1_HEIGHT, &dc, &dcMem);
  88. }
  89.  
  90.  
  91. // Set member variable to the bitmap ID corresponding to the currently
  92. //  selected custom AppWizard type
  93. void CCustomTypeDlg::SetBitmap()
  94. {
  95.     static UINT nBmps[] = {IDB_STEP1A, IDB_STEP1B, IDB_STEP1C};
  96.     ASSERT (m_nCustomType >= 0 && m_nCustomType < 3);
  97.     m_nBitmap = nBmps[m_nCustomType];
  98. }
  99.  
  100. // This handler allows us to dynamically change the bitmap as soon
  101. //  as a new custom AppWizard type is selected.  We also change the number
  102. //  of steps accordingly, since two of the options add an extra
  103. //  step after this one.
  104. BOOL CCustomTypeDlg::OnClickedRadio(UINT nID)
  105. {
  106.     switch(nID)
  107.     {
  108.     case IDC_ZAP:
  109.         m_nCustomType = CUSTOMTYPE_ZAP;
  110.         SetNumberOfSteps(2);
  111.         break;
  112.     case IDC_CUSTOM:
  113.         m_nCustomType = CUSTOMTYPE_BASE;
  114.         SetNumberOfSteps(1);
  115.         break;
  116.     case IDC_SEQUENCE:
  117.         m_nCustomType = CUSTOMTYPE_SEQUENCE;
  118.         SetNumberOfSteps(2);
  119.         break;
  120.     default:
  121.         ASSERT(FALSE);
  122.     }
  123.     SetBitmap();
  124.     sampleaw.SetCustomType(m_nCustomType);
  125.     EnableCustomSteps();
  126.  
  127.     // Invalidate the portion of this dialog on which we draw the picture
  128.     CRect rect(STEP1_LEFT, STEP1_TOP, STEP1_LEFT + STEP1_WIDTH, STEP1_TOP + STEP1_HEIGHT);
  129.     RedrawWindow(&rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  130.  
  131.     return TRUE;
  132. }
  133.  
  134. // If we're basing a custom AppWizard off of a project, that custom AppWizard
  135. //  must have 0 steps.  Thus, we must disable the "How many custom steps?"
  136. //  control when appropriate.
  137. void CCustomTypeDlg::EnableCustomSteps()
  138. {
  139.     BOOL bEnable = (m_nCustomType == CUSTOMTYPE_BASE || m_nCustomType == CUSTOMTYPE_SEQUENCE);
  140.     GetDlgItem(IDC_STC_STEPS)->EnableWindow(bEnable);
  141.     if (!GetDlgItem(IDC_STEPS)->EnableWindow(bEnable))
  142.         // Remember number of custom steps if it was previously enabled
  143.         GetDlgItem(IDC_STEPS)->GetWindowText(m_strLastCustomSteps);
  144.  
  145.     if (bEnable == TRUE)
  146.         GetDlgItem(IDC_STEPS)->SetWindowText(m_strLastCustomSteps);
  147.     else
  148.         GetDlgItem(IDC_STEPS)->SetWindowText(_T("0"));
  149. }
  150.  
  151. //  These must be in the same order as the corresponding radio buttons &
  152. //   CUSTOMTYPE enum
  153. static LPCTSTR lpszCustomTypeMacros[] =
  154. {
  155.     _T("CUSTOMTYPE_ZAP"),
  156.     _T("CUSTOMTYPE_SEQUENCE"),
  157.     _T("CUSTOMTYPE_BASE"),
  158. };
  159.  
  160. // Sets the macro corresponding to the custom AppWizard type (resets the others)
  161. void CCustomTypeDlg::SetCustomTypeMacros()
  162. {
  163.     for (UINT i=0; i < CUSTOMTYPE_MAX; i++)
  164.         DefineBoolMacro(lpszCustomTypeMacros[i], FALSE);
  165.  
  166.     ASSERT(m_nCustomType >= 0 && m_nCustomType <= 2);
  167.     DefineBoolMacro(lpszCustomTypeMacros[m_nCustomType], TRUE);
  168. }
  169.  
  170. // Sets the macro for the custom AppWizard's title
  171. void CCustomTypeDlg::DefineTitleMacro()
  172. {
  173.     DefineStringMacro(_T("AW_TITLE"), m_strTitle);
  174. }
  175.  
  176. // Set step-related template macros before dismissing
  177. BOOL CCustomTypeDlg::OnDismiss()
  178. {
  179.     ASSERT (0 <= m_nCustomType && m_nCustomType < CUSTOMTYPE_MAX);
  180.     if (!UpdateData(TRUE))
  181.         return FALSE;
  182.  
  183.     g_options.m_nCustomType = m_nCustomType;
  184.     g_options.m_nCustomSteps = m_nCustomSteps;
  185.     g_options.DefineDlgMacros();
  186.     SetCustomTypeMacros();
  187.     DefineTitleMacro();
  188.     return TRUE;
  189. }
  190.