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.

239 lines
6.1 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. PCWSTR pszHeaderTitle,
  60. PCWSTR pszHeaderSubTitle,
  61. PCWSTR pszTitle,
  62. OPTIONAL HINSTANCE hInstance)
  63. {
  64. Assert(unId);
  65. PROPSHEETPAGE psp = {0};
  66. HRSRC hrSrc = NULL;
  67. HGLOBAL hgRes = NULL;
  68. LPVOID lpv;
  69. psp.dwSize = sizeof(PROPSHEETPAGE);
  70. psp.dwFlags = dwFlags;
  71. if (!hInstance)
  72. {
  73. psp.hInstance = _Module.GetModuleInstance();
  74. psp.pszTemplate = MAKEINTRESOURCE(unId);
  75. }
  76. else
  77. {
  78. // If resource dll is external to netshell.dll
  79. hrSrc = FindResource(hInstance, MAKEINTRESOURCE(unId), RT_DIALOG);
  80. if (hrSrc)
  81. {
  82. hgRes = LoadResource(hInstance, hrSrc);
  83. if (hgRes)
  84. {
  85. lpv = LockResource(hgRes);
  86. if (lpv)
  87. {
  88. psp.hInstance = NULL;
  89. psp.dwFlags |= PSP_DLGINDIRECT;
  90. psp.pResource = (LPCDLGTEMPLATE)lpv;
  91. }
  92. else
  93. {
  94. TraceTag(ttidError, "LockResource failed");
  95. return NULL;
  96. }
  97. }
  98. else
  99. {
  100. TraceTag(ttidError, "LoadResource failed with error %ld", GetLastError());
  101. return NULL;
  102. }
  103. }
  104. else
  105. {
  106. TraceTag(ttidError, "FindResource failed with error %ld", GetLastError());
  107. return NULL;
  108. }
  109. }
  110. psp.pfnDlgProc = (DLGPROC)CPropSheetPage::DialogProc;
  111. psp.pfnCallback = static_cast<LPFNPSPCALLBACK>
  112. (CPropSheetPage::PropSheetPageProc);
  113. psp.lParam = (LPARAM)this;
  114. psp.pszHeaderTitle = pszHeaderTitle;
  115. psp.pszHeaderSubTitle = pszHeaderSubTitle;
  116. psp.pszTitle = pszTitle;
  117. return ::CreatePropertySheetPage(&psp);
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Member: CPropSheetPage::DialogProc
  122. //
  123. // Purpose: Dialog proc for ATL property sheet pages.
  124. //
  125. // Arguments:
  126. // hWnd [in]
  127. // uMsg [in] See the ATL documentation.
  128. // wParam [in]
  129. // lParam [in]
  130. //
  131. // Returns: LRESULT
  132. //
  133. // Author: danielwe 28 Feb 1997
  134. //
  135. // Notes:
  136. //
  137. LRESULT CALLBACK CPropSheetPage::DialogProc(HWND hWnd, UINT uMsg,
  138. WPARAM wParam, LPARAM lParam)
  139. {
  140. LRESULT lRes;
  141. PROPSHEETPAGE* ppsp;
  142. CPropSheetPage* pps;
  143. BOOL fRes = FALSE;
  144. if (uMsg == WM_INITDIALOG)
  145. {
  146. ppsp = (PROPSHEETPAGE *)lParam;
  147. pps = (CPropSheetPage *)ppsp->lParam;
  148. ::SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR) pps);
  149. pps->Attach(hWnd);
  150. }
  151. else
  152. {
  153. pps = (CPropSheetPage *)::GetWindowLongPtr(hWnd, DWLP_USER);
  154. // Until we get WM_INITDIALOG, just return FALSE
  155. if (!pps)
  156. return FALSE;
  157. }
  158. if (pps->ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lRes, 0))
  159. {
  160. switch (uMsg)
  161. {
  162. case WM_COMPAREITEM:
  163. case WM_VKEYTOITEM:
  164. case WM_CHARTOITEM:
  165. case WM_INITDIALOG:
  166. case WM_QUERYDRAGICON:
  167. return lRes;
  168. break;
  169. }
  170. ::SetWindowLongPtr(hWnd, DWLP_MSGRESULT, lRes);
  171. fRes = TRUE;
  172. }
  173. return fRes;
  174. }
  175. //+---------------------------------------------------------------------------
  176. //
  177. // Member: CPropSheetPage::PropSheetPageProc
  178. //
  179. // Purpose: PropSheetPageProc for ATL property sheet pages.
  180. //
  181. // Arguments:
  182. // hWnd [in]
  183. // uMsg [in] See Win32 documentation.
  184. // ppsp [in]
  185. //
  186. // Returns: UINT
  187. //
  188. // Author: billbe 6 Jul 1997
  189. //
  190. // Notes:
  191. //
  192. UINT CALLBACK CPropSheetPage::PropSheetPageProc(HWND hWnd, UINT uMsg,
  193. LPPROPSHEETPAGE ppsp)
  194. {
  195. CPropSheetPage* pps;
  196. // The this pointer was stored in the structure's lParam
  197. pps = reinterpret_cast<CPropSheetPage *>(ppsp->lParam);
  198. // This has to be valid since the CreatePage member fcn sets it
  199. Assert(pps);
  200. UINT uRet = TRUE;
  201. // call the correct handler based on uMsg
  202. //
  203. if (PSPCB_CREATE == uMsg)
  204. {
  205. uRet = pps->UCreatePageCallbackHandler();
  206. }
  207. else if (PSPCB_RELEASE == uMsg)
  208. {
  209. pps->DestroyPageCallbackHandler();
  210. }
  211. else
  212. {
  213. AssertSz(FALSE, "Invalid or new message sent to call back!");
  214. }
  215. return (uRet);
  216. }