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.

223 lines
4.2 KiB

  1. #include "shellprv.h"
  2. #include "ids.h"
  3. #include "basedlg.h"
  4. CBaseDlg::CBaseDlg(ULONG_PTR ulpAHelpIDsArray) :
  5. _cRef(1), _rgdwHelpIDsArray(ulpAHelpIDsArray)
  6. {}
  7. CBaseDlg::~CBaseDlg()
  8. {}
  9. LONG CBaseDlg::AddRef()
  10. {
  11. return (InterlockedIncrement(&_cRef));
  12. }
  13. LONG CBaseDlg::Release()
  14. {
  15. LONG cr;
  16. if (cr = InterlockedDecrement(&_cRef))
  17. return cr;
  18. else
  19. {
  20. delete this;
  21. return 0;
  22. }
  23. }
  24. INT_PTR CBaseDlg::DoModal(HINSTANCE hinst, LPTSTR pszResource, HWND hwndParent)
  25. {
  26. PROPSHEETPAGE psp;
  27. psp.lParam = (LPARAM)this;
  28. return DialogBoxParam(hinst, pszResource, hwndParent,
  29. CBaseDlg::BaseDlgWndProc, (LPARAM)&psp);
  30. }
  31. ULONG_PTR CBaseDlg::GetHelpIDsArray()
  32. {
  33. return _rgdwHelpIDsArray;
  34. }
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // Windows boiler plate code
  37. LRESULT CBaseDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  38. {
  39. LRESULT lRes = FALSE;
  40. switch (uMsg)
  41. {
  42. case WM_INITDIALOG:
  43. lRes = OnInitDialog(wParam, lParam);
  44. break;
  45. case WM_COMMAND:
  46. lRes = OnCommand(wParam, lParam);
  47. break;
  48. case WM_NOTIFY:
  49. lRes = OnNotify(wParam, lParam);
  50. break;
  51. case WM_DESTROY:
  52. lRes = OnDestroy(wParam, lParam);
  53. break;
  54. case WM_HELP:
  55. {
  56. lRes = OnHelp(wParam, lParam);
  57. break;
  58. }
  59. case WM_CONTEXTMENU:
  60. {
  61. lRes = OnContextMenu(wParam, lParam);
  62. break;
  63. }
  64. default:
  65. break;
  66. }
  67. return lRes;
  68. }
  69. LRESULT CBaseDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  70. {
  71. LRESULT lRes = FALSE;
  72. switch (GET_WM_COMMAND_ID(wParam, lParam))
  73. {
  74. case IDOK:
  75. lRes = OnOK(GET_WM_COMMAND_CMD(wParam, lParam));
  76. break;
  77. case IDCANCEL:
  78. lRes = OnCancel(GET_WM_COMMAND_CMD(wParam, lParam));
  79. break;
  80. default:
  81. break;
  82. }
  83. return lRes;
  84. }
  85. LRESULT CBaseDlg::OnNotify(WPARAM wParam, LPARAM lParam)
  86. {
  87. return 0;
  88. }
  89. LRESULT CBaseDlg::OnHelp(WPARAM wParam, LPARAM lParam)
  90. {
  91. HWND hwndItem = (HWND)((LPHELPINFO)lParam)->hItemHandle;
  92. int iCtrlID = GetDlgCtrlID(hwndItem);
  93. WinHelp(hwndItem, NULL, HELP_WM_HELP, GetHelpIDsArray());
  94. return TRUE;
  95. }
  96. LRESULT CBaseDlg::OnContextMenu(WPARAM wParam, LPARAM lParam)
  97. {
  98. BOOL lRes=FALSE;
  99. if (HTCLIENT == (int)SendMessage(_hwnd, WM_NCHITTEST, 0, lParam))
  100. {
  101. POINT pt;
  102. HWND hwndItem = NULL;
  103. int iCtrlID = 0;
  104. pt.x = GET_X_LPARAM(lParam);
  105. pt.y = GET_Y_LPARAM(lParam);
  106. ScreenToClient(_hwnd, &pt);
  107. hwndItem = ChildWindowFromPoint(_hwnd, pt);
  108. iCtrlID = GetDlgCtrlID(hwndItem);
  109. WinHelp((HWND)wParam, NULL, HELP_CONTEXTMENU, GetHelpIDsArray());
  110. lRes = TRUE;
  111. }
  112. else
  113. {
  114. lRes = FALSE;
  115. }
  116. return lRes;
  117. }
  118. LRESULT CBaseDlg::OnDestroy(WPARAM wParam, LPARAM lParam)
  119. {
  120. ResetHWND();
  121. SetWindowLongPtr(_hwnd, GWLP_USERDATA, NULL);
  122. Release();
  123. return FALSE;
  124. }
  125. //static
  126. BOOL_PTR CALLBACK CBaseDlg::BaseDlgWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  127. {
  128. CBaseDlg* pThis = (CBaseDlg*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  129. if (WM_INITDIALOG == uMsg)
  130. {
  131. pThis = (CBaseDlg*)(((PROPSHEETPAGE*)lParam)->lParam);
  132. if (pThis)
  133. {
  134. pThis->SetHWND(hwnd);
  135. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis);
  136. pThis->AddRef();
  137. SetForegroundWindow(hwnd);
  138. }
  139. }
  140. if (pThis)
  141. {
  142. return pThis->WndProc(uMsg, wParam, lParam);
  143. }
  144. else
  145. return 0;
  146. }
  147. UINT CALLBACK CBaseDlg::BaseDlgPropSheetCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  148. {
  149. UINT uResult = 0;
  150. CBaseDlg* pThis = (CBaseDlg*)ppsp->lParam;
  151. switch (uMsg)
  152. {
  153. case PSPCB_CREATE:
  154. {
  155. uResult = 1;
  156. break;
  157. }
  158. case PSPCB_RELEASE:
  159. {
  160. if (pThis)
  161. pThis->Release();
  162. break;
  163. }
  164. }
  165. return uResult;
  166. }
  167. LRESULT CBaseDlg::OnOK(WORD wNotif)
  168. {
  169. return FALSE;
  170. }
  171. LRESULT CBaseDlg::OnCancel(WORD wNotif)
  172. {
  173. return FALSE;
  174. }