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

  1. // customwz.cpp : Defines the initialization routines for the DLL.
  2. //
  3. // Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include <afxdllx.h>
  8. #include "customwz.h"
  9. #include "chooser.h"
  10. #include "sampleaw.h"
  11.  
  12. #ifdef _PSEUDO_DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. static AFX_EXTENSION_MODULE customwzDLL = { NULL, NULL };
  18.  
  19. extern "C" int APIENTRY
  20. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  21. {
  22.     if (dwReason == DLL_PROCESS_ATTACH)
  23.     {
  24.         TRACE0("CUSTMWZ.AWX Initializing!\n");
  25.  
  26.         // Extension DLL one-time initialization
  27.         AfxInitExtensionModule(customwzDLL, hInstance);
  28.  
  29.         // Insert this DLL into the resource chain
  30.         new CDynLinkLibrary(customwzDLL);
  31.  
  32.         // Register this custom AppWizard with MFCAPWZ.DLL
  33.         SetCustomAppWizClass(&sampleaw);
  34.     }
  35.     else if (dwReason == DLL_PROCESS_DETACH)
  36.     {
  37.         TRACE0("CUSTMWZ.AWX Terminating!\n");
  38.         AfxTermExtensionModule(customwzDLL);
  39.     }
  40.     return 1;   // ok
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Miscellaneous utility functions
  45.  
  46. // You may find the macro-setting functions useful in your own custom
  47. //  AppWizard.  Simply copy them to your own code, and replace references
  48. //  to "sampleaw" to your own CCustomAppWiz-derived class.
  49.  
  50. // These are generic macro-setting functions.  They set macros or remove
  51. //  them from the dictionary.
  52.  
  53. void DefineMacro(LPCTSTR lpszKey, LPCTSTR lpszValue)
  54. {
  55.     sampleaw.m_Dictionary[lpszKey] = lpszValue;
  56. }
  57.  
  58. void UndefMacro(LPCTSTR lpszKey)
  59. {
  60.     sampleaw.m_Dictionary.RemoveKey(lpszKey);
  61. }
  62.  
  63. // These are more specific macro-setting functions.  They set macros
  64. //  depending on the "type", and work correctly in $$BEGINLOOP/$$ENDLOOP
  65. //  blocks.
  66.  
  67. static void MakeKey(CString& strKey, int iItem)
  68. {
  69.     CString strOriginal = strKey;
  70.     strKey.Format(_T("%s_%d"), (LPCTSTR) strKey, iItem);
  71. }
  72.  
  73. void DefineIntMacro(LPCTSTR pszKey, int iValue)
  74. {
  75.     CString strValue;
  76.     strValue.Format(_T("%d"), iValue);
  77.     DefineMacro(pszKey, strValue);
  78. }
  79.  
  80. void DefineIntMacro(LPCTSTR pszKey, int iItem, int iValue)
  81. {
  82.     CString strKey(pszKey);
  83.     MakeKey(strKey, iItem);
  84.     DefineIntMacro(strKey, iValue);
  85. }
  86.  
  87. void DefineBoolMacro(LPCTSTR pszKey, BOOL bValue)
  88. {
  89.     if (bValue)
  90.         DefineMacro(pszKey, _T("1"));
  91.     else
  92.         UndefMacro(pszKey);
  93. }
  94.  
  95. void DefineBoolMacro(LPCTSTR pszKey, int iItem, BOOL bValue)
  96. {
  97.     CString strKey(pszKey);
  98.     MakeKey(strKey, iItem);
  99.     DefineBoolMacro(strKey, bValue);
  100. }
  101.  
  102. void DefineStringMacro(LPCTSTR pszKey, LPCTSTR pszValue)
  103. {
  104.     DefineMacro(pszKey, pszValue);
  105. }
  106.  
  107. void DefineStringMacro(LPCTSTR pszKey, int iItem, LPCTSTR pszValue)
  108. {
  109.     CString strKey(pszKey);
  110.     MakeKey(strKey, iItem);
  111.     DefineStringMacro(strKey, pszValue);
  112. }
  113.  
  114. // Report an error
  115. BOOL ReportError(UINT nIDP, LPCTSTR szArg)
  116. {
  117.     CString strPrompt;
  118.     AfxFormatString1(strPrompt, nIDP, szArg);
  119.     AfxMessageBox(strPrompt);
  120.     return FALSE;
  121. }
  122.  
  123. // Report an error and throw a user exception
  124. void ReportAndThrow(UINT nIDP, LPCTSTR szArg)
  125. {
  126.     ReportError(nIDP, szArg);
  127.     AfxThrowUserException();
  128. }
  129.