Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: wizbase.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _WIZBASE_H
  11. #define _WIZBASE_H
  12. #include "util.h"
  13. ////////////////////////////////////////////////////////////////////////////
  14. // FWD DECLARATIONS
  15. ////////////////////////////////////////////////////////////////////////////
  16. // CWizardBase
  17. class CWizardBase : public CPropertySheet
  18. {
  19. public:
  20. // construction/ destruction
  21. CWizardBase(UINT nWatermarkBitmapID, UINT nBannerBitmapID, UINT nTitleID = -1)
  22. {
  23. m_psh.hplWatermark = NULL;
  24. m_psh.dwFlags |= PSH_WIZARD | PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
  25. m_psh.pszbmWatermark = MAKEINTRESOURCE(nWatermarkBitmapID);
  26. m_psh.pszbmHeader = MAKEINTRESOURCE(nBannerBitmapID);
  27. m_bFwd = TRUE;
  28. m_nTitleID = nTitleID;
  29. }
  30. virtual ~CWizardBase(){}
  31. // message map
  32. BEGIN_MSG_MAP(CWizardBase)
  33. MESSAGE_HANDLER(WM_NCDESTROY, OnNcDestroy)
  34. END_MSG_MAP()
  35. // message handlers
  36. LRESULT OnNcDestroy(UINT uMsg, WPARAM wParam,
  37. LPARAM lParam, BOOL& bHandled)
  38. {
  39. // NOTICE: important!!!. BUG workaround.
  40. // We have to handle this message because we use ATL 2.1
  41. // The DECLARE_EMPTY_MSG_MAP() macro in the new ATLWIN.H
  42. // works only with the modified CWindowImplBase::WindowProc()
  43. return DefWindowProc(uMsg, wParam, lParam);
  44. }
  45. // helpers for setting wizard buttons
  46. void SetWizardButtonsFirst(BOOL bValid)
  47. {
  48. SetWizardButtons(bValid ? PSWIZB_NEXT : 0);
  49. }
  50. void SetWizardButtonsMiddle(BOOL bValid)
  51. {
  52. SetWizardButtons(bValid ? (PSWIZB_BACK|PSWIZB_NEXT) : PSWIZB_BACK);
  53. }
  54. void SetWizardButtonsLast(BOOL bValid)
  55. {
  56. SetWizardButtons(bValid ? (PSWIZB_BACK|PSWIZB_FINISH) : (PSWIZB_BACK|PSWIZB_DISABLEDFINISH));
  57. }
  58. // message box helpers
  59. int WizMessageBox(LPCTSTR lpszText, UINT nType = MB_OK)
  60. {
  61. CWString szTitle;
  62. szTitle.LoadFromResource(m_nTitleID);
  63. return MessageBox(lpszText, szTitle, nType);
  64. }
  65. int WizMessageBox(UINT nMsgID, UINT nType = MB_OK)
  66. {
  67. CWString szMsg;
  68. szMsg.LoadFromResource(nMsgID);
  69. return WizMessageBox(szMsg, nType);
  70. }
  71. // error message helpers
  72. void WizReportHRESULTError(LPCWSTR lpszMsg, HRESULT hr)
  73. {
  74. CWString szErrorString;
  75. if (GetStringFromHRESULTError(hr, szErrorString))
  76. {
  77. CWString szTemp;
  78. szTemp = lpszMsg;
  79. szTemp += L" ";
  80. szTemp += szErrorString;
  81. WizMessageBox(szTemp);
  82. }
  83. else
  84. {
  85. WizMessageBox(lpszMsg);
  86. }
  87. }
  88. void WizReportHRESULTError(UINT nStringID, HRESULT hr)
  89. {
  90. CWString szMsg;
  91. szMsg.LoadFromResource(nStringID);
  92. WizReportHRESULTError(szMsg, hr);
  93. }
  94. void WizReportWin32Error(LPCWSTR lpszMsg, DWORD dwErr)
  95. {
  96. CWString szErrorString;
  97. if (GetStringFromWin32Error(dwErr, szErrorString))
  98. {
  99. CWString szTemp;
  100. szTemp = lpszMsg;
  101. szTemp += L" ";
  102. szTemp += szErrorString;
  103. WizMessageBox(szTemp);
  104. }
  105. else
  106. {
  107. WizMessageBox(lpszMsg);
  108. }
  109. }
  110. void WizReportWin32Error(UINT nStringID, DWORD dwErr)
  111. {
  112. CWString szMsg;
  113. szMsg.LoadFromResource(nStringID);
  114. WizReportWin32Error(szMsg, dwErr);
  115. }
  116. public:
  117. BOOL m_bFwd;
  118. private:
  119. UINT m_nTitleID;
  120. };
  121. ////////////////////////////////////////////////////////////////////////////
  122. // CWizPageBase
  123. template <class T>
  124. class CWizPageBase : public CPropertyPageImpl<T>
  125. {
  126. public:
  127. CWizPageBase(CWizardBase* pWiz)
  128. {
  129. m_pWiz = pWiz;
  130. m_lpszHeaderTitleBuf = NULL;
  131. m_lpszHeaderSubTitleBuf = NULL;
  132. m_nPrevPageID = 0;
  133. }
  134. ~CWizPageBase()
  135. {
  136. if (m_lpszHeaderTitleBuf != NULL)
  137. delete[] m_lpszHeaderTitleBuf;
  138. if (m_lpszHeaderSubTitleBuf != NULL)
  139. delete[] m_lpszHeaderSubTitleBuf;
  140. }
  141. CWizardBase* GetWizard() { return m_pWiz; }
  142. void InitWiz97(BOOL bHideHeader, UINT nTitleID=0, UINT nSubTitleID=0)
  143. {
  144. if (bHideHeader)
  145. m_psp.dwFlags |= PSP_HIDEHEADER;
  146. else
  147. {
  148. int nBufferMax = 128;
  149. if (nTitleID != 0)
  150. {
  151. m_lpszHeaderTitleBuf = new TCHAR[nBufferMax];
  152. if( m_lpszHeaderTitleBuf )
  153. {
  154. if (LoadStringHelper(nTitleID, m_lpszHeaderTitleBuf, nBufferMax))
  155. {
  156. m_psp.dwFlags |= PSP_USEHEADERTITLE;
  157. m_psp.pszHeaderTitle = m_lpszHeaderTitleBuf;
  158. }
  159. }
  160. }
  161. if (nSubTitleID != 0)
  162. {
  163. m_lpszHeaderSubTitleBuf = new TCHAR[nBufferMax];
  164. if(m_lpszHeaderSubTitleBuf )
  165. {
  166. LoadStringHelper(nSubTitleID, m_lpszHeaderSubTitleBuf, nBufferMax);
  167. m_psp.dwFlags |= PSP_USEHEADERSUBTITLE;
  168. m_psp.pszHeaderSubTitle = m_lpszHeaderSubTitleBuf;
  169. }
  170. }
  171. }
  172. }
  173. public:
  174. // standard wizard message handlers
  175. LRESULT OnWizardBack()
  176. {
  177. m_pWiz->m_bFwd = FALSE;
  178. UINT nTempPrevPageID = m_nPrevPageID;
  179. m_nPrevPageID = 0;
  180. return nTempPrevPageID;
  181. }
  182. LRESULT OnWizardNext()
  183. {
  184. OnWizardNextHelper();
  185. return 0;
  186. }
  187. void OnWizardNextHelper()
  188. {
  189. m_pWiz->m_bFwd = TRUE;
  190. }
  191. public:
  192. UINT m_nPrevPageID;
  193. private:
  194. CWizardBase* m_pWiz;
  195. LPTSTR m_lpszHeaderTitleBuf;
  196. LPTSTR m_lpszHeaderSubTitleBuf;
  197. };
  198. #endif // _WIZBASE_H