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.

309 lines
8.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: ModalDlg.cpp
  4. //
  5. // Module: Connection manager
  6. //
  7. // Synopsis: Implementation of the classes CWindowWithHelp, CModalDlg
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: fengsun Created 02/17/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. //+----------------------------------------------------------------------------
  15. //
  16. // Function: CWindowWithHelp::CWindowWithHelp
  17. //
  18. // Synopsis: Constructor
  19. //
  20. // Arguments: const DWORD* pHelpPairs - The pairs of control-ID/Help-ID
  21. // const TCHAR* lpszHelpFile - The help file name, default is NULL
  22. // Call also call SetHelpFileName() to provide help file
  23. //
  24. // Returns: Nothing
  25. //
  26. // History: fengsun Created Header 2/20/98
  27. //
  28. //+----------------------------------------------------------------------------
  29. CWindowWithHelp::CWindowWithHelp(const DWORD* pHelpPairs, const TCHAR* lpszHelpFile)
  30. {
  31. m_lpszHelpFile = NULL;
  32. m_hWnd = NULL;
  33. m_pHelpPairs = pHelpPairs;
  34. if (lpszHelpFile)
  35. {
  36. SetHelpFileName(lpszHelpFile);
  37. }
  38. }
  39. //+----------------------------------------------------------------------------
  40. //
  41. // Function: CWindowWithHelp::~CWindowWithHelp
  42. //
  43. // Synopsis: Destructor
  44. //
  45. // Arguments: None
  46. //
  47. // Returns: Nothing
  48. //
  49. // History: Created Header 2/20/98
  50. //
  51. //+----------------------------------------------------------------------------
  52. CWindowWithHelp::~CWindowWithHelp()
  53. {
  54. CmFree(m_lpszHelpFile);
  55. }
  56. //+----------------------------------------------------------------------------
  57. //
  58. // Function: CWindowWithHelp::SetHelpFileName
  59. //
  60. // Synopsis: Set the help file name of the window
  61. //
  62. // Arguments: const TCHAR* lpszHelpFile - the help file name to set
  63. //
  64. // Returns: Nothing
  65. //
  66. // History: fengsun Created Header 2/20/98
  67. //
  68. //+----------------------------------------------------------------------------
  69. void CWindowWithHelp::SetHelpFileName(const TCHAR* lpszHelpFile)
  70. {
  71. MYDBGASSERT(m_lpszHelpFile == NULL);
  72. MYDBGASSERT(lpszHelpFile);
  73. CmFree(m_lpszHelpFile);
  74. m_lpszHelpFile = NULL;
  75. if (lpszHelpFile && lpszHelpFile[0])
  76. {
  77. m_lpszHelpFile = CmStrCpyAlloc(lpszHelpFile);
  78. MYDBGASSERT(m_lpszHelpFile);
  79. }
  80. }
  81. //+----------------------------------------------------------------------------
  82. //
  83. // Function: CWindowWithHelp::HasContextHelp
  84. //
  85. // Synopsis: Whether a control has context help
  86. //
  87. // Arguments: HWND hWndCtrl - The window handle of the control
  88. //
  89. // Returns: BOOL - TRUE , if the control has context help
  90. //
  91. // History: fengsun Created Header 2/20/98
  92. //
  93. //+----------------------------------------------------------------------------
  94. BOOL CWindowWithHelp::HasContextHelp(HWND hWndCtrl) const
  95. {
  96. if (hWndCtrl == NULL || m_pHelpPairs == NULL)
  97. {
  98. return FALSE;
  99. }
  100. //
  101. // looks through the help pairs for the control
  102. //
  103. for (int i=0; m_pHelpPairs[i]!=0; i+=2)
  104. {
  105. if (m_pHelpPairs[i] == (DWORD)GetDlgCtrlID(hWndCtrl))
  106. {
  107. CMTRACE3(TEXT("HasContextHelp() - hwndCtrl %d has Ctrl ID %d and context help ID %d"), hWndCtrl, m_pHelpPairs[i], m_pHelpPairs[i+1]);
  108. return TRUE;
  109. }
  110. }
  111. CMTRACE1(TEXT("HasContextHelp() - hwndCtrl %d has no context help"), hWndCtrl);
  112. return FALSE;
  113. }
  114. //+----------------------------------------------------------------------------
  115. //
  116. // Function: CWindowWithHelp::OnHelp
  117. //
  118. // Synopsis: Call on WM_HELP message. Which means F1 is pressed
  119. //
  120. // Arguments: const HELPINFO* pHelpInfo - lParam of WM_HELP
  121. //
  122. // Returns: Nothing
  123. //
  124. // History: Created Header 2/17/98
  125. //
  126. //+----------------------------------------------------------------------------
  127. void CWindowWithHelp::OnHelp(const HELPINFO* pHelpInfo)
  128. {
  129. //
  130. // If help file exist and the help id exist WinHelp
  131. //
  132. if (m_lpszHelpFile && m_lpszHelpFile[0] && HasContextHelp((HWND) pHelpInfo->hItemHandle))
  133. {
  134. CmWinHelp((HWND)pHelpInfo->hItemHandle, (HWND)pHelpInfo->hItemHandle, m_lpszHelpFile, HELP_WM_HELP,
  135. (ULONG_PTR)(LPSTR)m_pHelpPairs);
  136. }
  137. }
  138. //+----------------------------------------------------------------------------
  139. //
  140. // Function: CWindowWithHelp::OnContextMenu
  141. //
  142. // Synopsis: called upon WM_CONTEXTMENU message (Right click or '?')
  143. //
  144. // Arguments: HWND hWnd - Handle to the window in which the user right clicked
  145. // the mouse
  146. // POINT& pos - position of the cursor
  147. //
  148. // Returns: BOOL, TRUE if the message is processed
  149. //
  150. // History: fengsun Created Header 2/17/98
  151. //
  152. //+----------------------------------------------------------------------------
  153. BOOL CWindowWithHelp::OnContextMenu(HWND hWnd, POINT& pos)
  154. {
  155. ScreenToClient(m_hWnd, &pos);
  156. //
  157. // If more than one child window contains the specified point, ChildWindowFromPoint()
  158. // returns a handle to the first window in the list that contains the point.
  159. // This becomes a problem if we have controls inside groupbox
  160. //
  161. HWND hWndChild = ChildWindowFromPointEx(m_hWnd, pos, CWP_SKIPINVISIBLE);
  162. if (m_lpszHelpFile && m_lpszHelpFile[0] && hWndChild && HasContextHelp(hWndChild))
  163. {
  164. CMTRACE2(TEXT("OnContextMenu() - Calling WinHelp hWnd is %d, m_hWnd is %d"), hWnd, m_hWnd);
  165. CmWinHelp(hWnd, hWndChild, m_lpszHelpFile, HELP_CONTEXTMENU, (ULONG_PTR)m_pHelpPairs);
  166. return TRUE;
  167. }
  168. return FALSE; // Return FALSE, DefaultWindowProc will handle this message then.
  169. }
  170. //+----------------------------------------------------------------------------
  171. //
  172. // Function: CModalDlg::DoDialogBox
  173. //
  174. // Synopsis: Same as DialogBox
  175. //
  176. // Arguments: HINSTANCE hInstance - Same as ::DialogBox
  177. // LPCTSTR lpTemplateName -
  178. // HWND hWndParent -
  179. //
  180. // Returns: int - Same as DialogBox
  181. //
  182. // History: Created Header 2/17/98
  183. //
  184. //+----------------------------------------------------------------------------
  185. INT_PTR CModalDlg::DoDialogBox(HINSTANCE hInstance,
  186. LPCTSTR lpTemplateName,
  187. HWND hWndParent)
  188. {
  189. INT_PTR iRet = ::DialogBoxParamU(hInstance, lpTemplateName, hWndParent,
  190. ModalDialogProc, (LPARAM)this);
  191. m_hWnd = NULL;
  192. return iRet;
  193. }
  194. //+----------------------------------------------------------------------------
  195. //
  196. // Function: CModalDlg::ModalDialogProc
  197. //
  198. // Synopsis: The dialog window procedure for all dialogbox derived
  199. //
  200. // Arguments: HWND hwndDlg -
  201. // UINT uMsg -
  202. // WPARAM wParam -
  203. // LPARAM lParam -
  204. //
  205. // Returns: BOOL CALLBACK -
  206. //
  207. // History: Created Header 2/17/98
  208. //
  209. //+----------------------------------------------------------------------------
  210. INT_PTR CALLBACK CModalDlg::ModalDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam, LPARAM lParam)
  211. {
  212. CModalDlg* pDlg;
  213. //
  214. // Save the object pointer on WM_INITDIALOG
  215. // lParam is the pointer
  216. //
  217. if (uMsg == WM_INITDIALOG)
  218. {
  219. pDlg = (CModalDlg*) lParam;
  220. MYDBGASSERT(lParam);
  221. MYDBGASSERT(((CModalDlg*)lParam)->m_hWnd == NULL);
  222. //
  223. // Save the object pointer, this is implementation detail
  224. // The user of this class should not be aware of this
  225. //
  226. ::SetWindowLongU(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
  227. pDlg->m_hWnd = hwndDlg;
  228. }
  229. else
  230. {
  231. pDlg = (CModalDlg*)GetWindowLongU(hwndDlg, DWLP_USER);
  232. //
  233. // some msgs can come before WM_INITDIALOG
  234. //
  235. if (pDlg == NULL)
  236. {
  237. return FALSE;
  238. }
  239. }
  240. MYDBGASSERT(pDlg->m_hWnd == hwndDlg);
  241. ASSERT_VALID(pDlg);
  242. switch(uMsg)
  243. {
  244. case WM_INITDIALOG:
  245. return pDlg->OnInitDialog();
  246. case WM_HELP:
  247. pDlg->OnHelp((LPHELPINFO)lParam);
  248. return TRUE;
  249. case WM_CONTEXTMENU:
  250. {
  251. POINT pos = {LOWORD(lParam), HIWORD(lParam)};
  252. return pDlg->OnContextMenu((HWND) wParam, pos);
  253. }
  254. case WM_COMMAND:
  255. switch (LOWORD(wParam))
  256. {
  257. case IDOK:
  258. pDlg->OnOK();
  259. return FALSE;
  260. case IDCANCEL:
  261. pDlg->OnCancel();
  262. return FALSE;
  263. default:
  264. return pDlg->OnOtherCommand(wParam,lParam);
  265. }
  266. default:
  267. return pDlg->OnOtherMessage(uMsg, wParam, lParam);
  268. }
  269. }