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.

196 lines
4.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C A T L P S . C P P
  7. //
  8. // Contents: Class implementation for ATL-like property sheet page object.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 28 Feb 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.h>
  16. #pragma hdrstop
  17. #include <atlbase.h>
  18. extern CComModule _Module; // required by atlcom.h
  19. #include <atlcom.h>
  20. #ifdef SubclassWindow
  21. #undef SubclassWindow
  22. #endif
  23. #include <atlwin.h>
  24. #include "ncatlps.h"
  25. CPropSheetPage::~CPropSheetPage ()
  26. {
  27. // If we are attached to a window, DWL_USER contains a pointer to this.
  28. // Remove it since we are going away.
  29. //
  30. if (m_hWnd)
  31. {
  32. const CPropSheetPage* pps;
  33. pps = (CPropSheetPage *) ::GetWindowLongPtr(m_hWnd, DWLP_USER);
  34. if (pps)
  35. {
  36. AssertSz (pps == this, "Why isn't DWL_USER equal to 'this'?");
  37. ::SetWindowLongPtr(m_hWnd, DWLP_USER, NULL);
  38. }
  39. }
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Member: CPropSheetPage::CreatePage
  44. //
  45. // Purpose: Method to quickly create a property page.
  46. //
  47. // Arguments:
  48. // unId [in] IDD of dialog resource ID
  49. // dwFlags [in] Additional flags to use in the dwFlags field of the
  50. // PROPSHEETPAGE struct.
  51. //
  52. // Returns: HPROPSHEETPAGE
  53. //
  54. // Author: shaunco 28 Feb 1997
  55. //
  56. // Notes:
  57. //
  58. HPROPSHEETPAGE CPropSheetPage::CreatePage(UINT unId, DWORD dwFlags,
  59. PCTSTR pszHeaderTitle,
  60. PCTSTR pszHeaderSubTitle,
  61. PCTSTR pszTitle)
  62. {
  63. Assert(unId);
  64. PROPSHEETPAGE psp = {0};
  65. psp.dwSize = sizeof(PROPSHEETPAGE);
  66. psp.dwFlags = dwFlags;
  67. psp.hInstance = _Module.GetModuleInstance();
  68. psp.pszTemplate = MAKEINTRESOURCE(unId);
  69. psp.pfnDlgProc = (DLGPROC)CPropSheetPage::DialogProc;
  70. psp.pfnCallback = static_cast<LPFNPSPCALLBACK>
  71. (CPropSheetPage::PropSheetPageProc);
  72. psp.lParam = (LPARAM)this;
  73. psp.pszHeaderTitle = pszHeaderTitle;
  74. psp.pszHeaderSubTitle = pszHeaderSubTitle;
  75. psp.pszTitle = pszTitle;
  76. return ::CreatePropertySheetPage(&psp);
  77. }
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Member: CPropSheetPage::DialogProc
  81. //
  82. // Purpose: Dialog proc for ATL property sheet pages.
  83. //
  84. // Arguments:
  85. // hWnd [in]
  86. // uMsg [in] See the ATL documentation.
  87. // wParam [in]
  88. // lParam [in]
  89. //
  90. // Returns: LRESULT
  91. //
  92. // Author: danielwe 28 Feb 1997
  93. //
  94. // Notes:
  95. //
  96. LRESULT CALLBACK CPropSheetPage::DialogProc(HWND hWnd, UINT uMsg,
  97. WPARAM wParam, LPARAM lParam)
  98. {
  99. LRESULT lRes;
  100. PROPSHEETPAGE* ppsp;
  101. CPropSheetPage* pps;
  102. BOOL fRes = FALSE;
  103. if (uMsg == WM_INITDIALOG)
  104. {
  105. ppsp = (PROPSHEETPAGE *)lParam;
  106. pps = (CPropSheetPage *)ppsp->lParam;
  107. ::SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR) pps);
  108. pps->Attach(hWnd);
  109. }
  110. else
  111. {
  112. pps = (CPropSheetPage *)::GetWindowLongPtr(hWnd, DWLP_USER);
  113. // Until we get WM_INITDIALOG, just return FALSE
  114. if (!pps)
  115. return FALSE;
  116. }
  117. if (pps->ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lRes, 0))
  118. {
  119. switch (uMsg)
  120. {
  121. case WM_COMPAREITEM:
  122. case WM_VKEYTOITEM:
  123. case WM_CHARTOITEM:
  124. case WM_INITDIALOG:
  125. case WM_QUERYDRAGICON:
  126. return lRes;
  127. break;
  128. }
  129. ::SetWindowLongPtr(hWnd, DWLP_MSGRESULT, lRes);
  130. fRes = TRUE;
  131. }
  132. return fRes;
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // Member: CPropSheetPage::PropSheetPageProc
  137. //
  138. // Purpose: PropSheetPageProc for ATL property sheet pages.
  139. //
  140. // Arguments:
  141. // hWnd [in]
  142. // uMsg [in] See Win32 documentation.
  143. // ppsp [in]
  144. //
  145. // Returns: UINT
  146. //
  147. // Author: billbe 6 Jul 1997
  148. //
  149. // Notes:
  150. //
  151. UINT CALLBACK CPropSheetPage::PropSheetPageProc(HWND hWnd, UINT uMsg,
  152. LPPROPSHEETPAGE ppsp)
  153. {
  154. CPropSheetPage* pps;
  155. // The this pointer was stored in the structure's lParam
  156. pps = reinterpret_cast<CPropSheetPage *>(ppsp->lParam);
  157. // This has to be valid since the CreatePage member fcn sets it
  158. Assert(pps);
  159. UINT uRet = TRUE;
  160. // call the correct handler based on uMsg
  161. //
  162. if (PSPCB_CREATE == uMsg)
  163. {
  164. uRet = pps->UCreatePageCallbackHandler();
  165. }
  166. else if (PSPCB_RELEASE == uMsg)
  167. {
  168. pps->DestroyPageCallbackHandler();
  169. }
  170. else
  171. {
  172. AssertSz(FALSE, "Invalid or new message sent to call back!");
  173. }
  174. return (uRet);
  175. }