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.

253 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name :
  4. WizTempl.h
  5. Abstract:
  6. Template for wizard pages
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. 11/9/2000 sergeia Initial creation
  13. --*/
  14. #ifndef _WIZTEMPL_H
  15. #define _WIZTEMPL_H
  16. #ifndef _PRSHT_H_
  17. #error WizTempl.h requires prsht.h to be included first
  18. #endif
  19. #pragma comment(lib, "comctl32.lib")
  20. template <class T>
  21. class CWizardPageImpl : public CDialogImplBase
  22. {
  23. public:
  24. PROPSHEETPAGE m_psp;
  25. HPROPSHEETPAGE m_hpsp;
  26. CComBSTR m_bstrTitle;
  27. CComBSTR m_bstrSubTitle;
  28. operator PROPSHEETPAGE*() { return &m_psp; }
  29. CWizardPageImpl(
  30. IN bool i_bShowHeader
  31. )
  32. :m_hpsp(NULL)
  33. {
  34. ZeroMemory(&m_psp, sizeof m_psp);
  35. m_psp.dwSize = sizeof m_psp;
  36. m_psp.hInstance = _Module.GetResourceInstance();
  37. m_psp.pszTemplate = MAKEINTRESOURCE(T::IDD);
  38. m_psp.pfnDlgProc = (DLGPROC)T::StartDialogProc;
  39. m_psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
  40. m_psp.pfnCallback = T::PropPageCallback;
  41. if ( false == i_bShowHeader)
  42. {
  43. m_psp.dwFlags |= PSP_HIDEHEADER;
  44. }
  45. m_psp.lParam = (LPARAM)this;
  46. }
  47. void SetHeaderTitle(
  48. IN LPCTSTR i_lpszHeaderTitle
  49. )
  50. {
  51. m_psp.dwFlags |= PSP_USEHEADERTITLE; // Header title. Wizard 97
  52. m_bstrTitle = i_lpszHeaderTitle;
  53. m_psp.pszHeaderTitle = m_bstrTitle;
  54. }
  55. void SetHeaderSubTitle(
  56. IN LPCTSTR i_lpszHeaderSubTitle
  57. )
  58. {
  59. m_psp.dwFlags |= PSP_USEHEADERSUBTITLE; // Header sub title. Wizard 97
  60. m_bstrSubTitle = i_lpszHeaderSubTitle;
  61. m_psp.pszHeaderSubTitle = m_bstrSubTitle;
  62. }
  63. static UINT CALLBACK PropPageCallback(
  64. HWND hWnd,
  65. UINT uMsg,
  66. LPPROPSHEETPAGE ppsp
  67. )
  68. {
  69. if(uMsg == PSPCB_CREATE)
  70. {
  71. _ASSERTE(hWnd == NULL);
  72. CDialogImplBase* pPage = (CDialogImplBase*)ppsp->lParam;
  73. _Module.AddCreateWndData(&pPage->m_thunk.cd, pPage);
  74. }
  75. else if(uMsg == PSPCB_RELEASE)
  76. {
  77. CWizardPageImpl* pPage = (CWizardPageImpl*)ppsp->lParam;
  78. pPage->Delete();
  79. }
  80. return 1;
  81. }
  82. virtual HPROPSHEETPAGE Create()
  83. {
  84. return (m_hpsp = ::CreatePropertySheetPage(&m_psp));
  85. }
  86. // Implement this in derived class to do clean up when property
  87. // Page is closed.
  88. virtual void Delete()
  89. {
  90. return;
  91. }
  92. virtual BOOL EndDialog(int)
  93. {
  94. // Calling ::EndDialog will close the whole sheet
  95. _ASSERTE(FALSE);
  96. return FALSE;
  97. }
  98. BEGIN_MSG_MAP(CWizardPageImpl<T>)
  99. MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
  100. END_MSG_MAP()
  101. LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  102. {
  103. _ASSERTE(::IsWindow(m_hWnd));
  104. NMHDR* pNMHDR = (NMHDR*)lParam;
  105. _ASSERT(NULL != pNMHDR);
  106. if (NULL == pNMHDR)
  107. {
  108. bHandled = FALSE;
  109. return 1;
  110. }
  111. // Ignore messages not from the page/sheet itself
  112. if(pNMHDR->hwndFrom != m_hWnd && pNMHDR->hwndFrom != ::GetParent(m_hWnd))
  113. {
  114. bHandled = FALSE;
  115. return 1;
  116. }
  117. T* pT = (T*)this;
  118. LRESULT lResult = 0;
  119. switch(pNMHDR->code) // Used to call actual methods
  120. {
  121. case PSN_SETACTIVE:
  122. lResult = pT->OnSetActive() ? 0 : -1;
  123. break;
  124. case PSN_KILLACTIVE:
  125. lResult = !pT->OnKillActive();
  126. break;
  127. case PSN_RESET:
  128. pT->OnReset();
  129. break;
  130. case PSN_QUERYCANCEL:
  131. lResult = !pT->OnQueryCancel();
  132. break;
  133. case PSN_WIZNEXT:
  134. lResult = !pT->OnWizardNext();
  135. break;
  136. case PSN_WIZBACK:
  137. lResult = !pT->OnWizardBack();
  138. break;
  139. case PSN_WIZFINISH:
  140. lResult = !pT->OnWizardFinish();
  141. break;
  142. case PSN_HELP:
  143. lResult = pT->OnHelp();
  144. break;
  145. case PSN_APPLY:
  146. lResult = pT->OnApply() ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE;
  147. break;
  148. default:
  149. bHandled = FALSE; // not handled
  150. }
  151. return lResult;
  152. }
  153. BOOL OnSetActive()
  154. {
  155. return TRUE;
  156. }
  157. BOOL OnKillActive()
  158. {
  159. return TRUE;
  160. }
  161. void OnReset()
  162. {
  163. }
  164. BOOL OnQueryCancel()
  165. {
  166. return TRUE; // ok to cancel
  167. }
  168. BOOL OnWizardBack()
  169. {
  170. return TRUE;
  171. }
  172. BOOL OnWizardNext()
  173. {
  174. return TRUE;
  175. }
  176. BOOL OnWizardFinish()
  177. {
  178. return TRUE;
  179. }
  180. BOOL OnHelp()
  181. {
  182. return TRUE;
  183. }
  184. BOOL OnApply()
  185. {
  186. return TRUE;
  187. }
  188. };
  189. #endif //_WIZTEMPL_H