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.

248 lines
4.0 KiB

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