Leaked source code of windows server 2003
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.

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