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.

280 lines
7.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1997 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DlgHelp.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CDialogHelp class.
  10. //
  11. // Author:
  12. // David Potter (davidp) February 6, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "DlgHelp.h"
  21. #include "TraceTag.h"
  22. #include "resource.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Global Variables
  30. /////////////////////////////////////////////////////////////////////////////
  31. #ifdef _DEBUG
  32. CTraceTag g_tagDlgHelp(_T("Help"), _T("DLG HELP"), 0);
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CDialogHelp class
  36. /////////////////////////////////////////////////////////////////////////////
  37. IMPLEMENT_DYNAMIC(CDialogHelp, CObject)
  38. /////////////////////////////////////////////////////////////////////////////
  39. //++
  40. //
  41. // CDialogHelp::CDialogHelp
  42. //
  43. // Routine Description:
  44. // Constructor.
  45. //
  46. // Arguments:
  47. // pmap [IN] Map array mapping control IDs to help IDs.
  48. // dwMask [IN] Mask to use for the low word of the help ID.
  49. //
  50. // Return Value:
  51. // None.
  52. //
  53. //--
  54. /////////////////////////////////////////////////////////////////////////////
  55. CDialogHelp::CDialogHelp(IN const CMapCtrlToHelpID * pmap, IN DWORD dwMask)
  56. {
  57. ASSERT(pmap != NULL);
  58. CommonConstruct();
  59. m_pmap = pmap;
  60. m_dwMask = dwMask;
  61. } //*** CDialogHelp::CDialogHelp()
  62. /////////////////////////////////////////////////////////////////////////////
  63. //++
  64. //
  65. // CDialogHelp::CommonConstruct
  66. //
  67. // Routine Description:
  68. // Do common construction.
  69. //
  70. // Arguments:
  71. // None.
  72. //
  73. // Return Value:
  74. // None.
  75. //
  76. //--
  77. /////////////////////////////////////////////////////////////////////////////
  78. void CDialogHelp::CommonConstruct(void)
  79. {
  80. m_pmap = NULL;
  81. } //*** CDialogHelp::CommonConstruct()
  82. /////////////////////////////////////////////////////////////////////////////
  83. //++
  84. //
  85. // CDialogHelp::NHelpFromCtrlID
  86. //
  87. // Routine Description:
  88. // Return the help ID from a control ID.
  89. //
  90. // Arguments:
  91. // nCtrlID [IN] ID of control to search for.
  92. //
  93. // Return Value:
  94. // nHelpID Help ID associated with the control.
  95. //
  96. //--
  97. /////////////////////////////////////////////////////////////////////////////
  98. DWORD CDialogHelp::NHelpFromCtrlID(IN DWORD nCtrlID) const
  99. {
  100. DWORD nHelpID = 0;
  101. const CMapCtrlToHelpID * pmap = Pmap();
  102. ASSERT(pmap != NULL);
  103. ASSERT(nCtrlID != 0);
  104. for ( ; pmap->m_nCtrlID != 0 ; pmap++)
  105. {
  106. if (pmap->m_nCtrlID == nCtrlID)
  107. {
  108. if (pmap->m_nHelpCtrlID == -1)
  109. nHelpID = (DWORD) -1;
  110. else
  111. //nHelpID = (pmap->m_nHelpCtrlID << 16) | (DwMask() & 0xFFFF);
  112. nHelpID = pmap->m_nHelpCtrlID;
  113. break;
  114. } // if: found a match
  115. } // for: each control
  116. Trace(g_tagDlgHelp, _T("NHelpFromCtrlID() - nCtrlID = %x, nHelpID = %x"), nCtrlID, nHelpID);
  117. return nHelpID;
  118. } //*** CDialogHelp::NHelpFromCtrlID()
  119. /////////////////////////////////////////////////////////////////////////////
  120. //++
  121. //
  122. // CDialogHelp::OnContextMenu
  123. //
  124. // Routine Description:
  125. // Handler for the WM_CONTEXTMENU message.
  126. //
  127. // Arguments:
  128. // pWnd Window in which user clicked the right mouse button.
  129. // point Position of the cursor, in screen coordinates.
  130. //
  131. // Return Value:
  132. // TRUE Help processed.
  133. // FALSE Help not processed.
  134. //
  135. //--
  136. /////////////////////////////////////////////////////////////////////////////
  137. void CDialogHelp::OnContextMenu(CWnd * pWnd, CPoint point)
  138. {
  139. CWnd * pwndChild;
  140. CPoint ptDialog;
  141. DWORD nHelpID = 0;
  142. ASSERT(pWnd != NULL);
  143. m_nHelpID = 0;
  144. // Convert the point into dialog coordinates.
  145. ptDialog = point;
  146. pWnd->ScreenToClient(&ptDialog);
  147. // Find the control the cursor is over.
  148. {
  149. DWORD nCtrlID;
  150. pwndChild = pWnd->ChildWindowFromPoint(ptDialog);
  151. if (pwndChild != NULL && pwndChild->m_hWnd != NULL)
  152. {
  153. nCtrlID = pwndChild->GetDlgCtrlID();
  154. if (nCtrlID != 0)
  155. nHelpID = NHelpFromCtrlID(nCtrlID);
  156. } // if: over a child window
  157. } // Find the control the cursor is over
  158. // Display a popup menu.
  159. if ((nHelpID != 0) && (nHelpID != -1))
  160. {
  161. CString strMenu;
  162. CMenu menu;
  163. try
  164. {
  165. strMenu.LoadString(IDS_MENU_WHATS_THIS);
  166. } // try
  167. catch (CMemoryException * pme)
  168. {
  169. pme->Delete();
  170. return;
  171. } // catch: CMemoryException
  172. if (menu.CreatePopupMenu())
  173. {
  174. if (menu.AppendMenu(MF_STRING | MF_ENABLED, ID_HELP, strMenu))
  175. {
  176. m_nHelpID = nHelpID;
  177. menu.TrackPopupMenu(
  178. TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  179. point.x,
  180. point.y,
  181. AfxGetMainWnd()
  182. );
  183. } // if: menu item added successfully
  184. menu.DestroyMenu();
  185. } // if: popup menu created successfully
  186. } // if: over a child window of this dialog with a tabstop
  187. } //*** CDialogHelp::OnContextMenu()
  188. /////////////////////////////////////////////////////////////////////////////
  189. //++
  190. //
  191. // CDialogHelp::OnHelpInfo
  192. //
  193. // Routine Description:
  194. // Handler for the WM_HELPINFO message.
  195. //
  196. // Arguments:
  197. // pHelpInfo Structure containing info about displaying help.
  198. //
  199. // Return Value:
  200. // TRUE Help processed.
  201. // FALSE Help not processed.
  202. //
  203. //--
  204. /////////////////////////////////////////////////////////////////////////////
  205. BOOL CDialogHelp::OnHelpInfo(HELPINFO * pHelpInfo)
  206. {
  207. // If this is for a control, display control-specific help.
  208. if ((pHelpInfo->iContextType == HELPINFO_WINDOW)
  209. && (pHelpInfo->iCtrlId != 0))
  210. {
  211. DWORD nHelpID = NHelpFromCtrlID(pHelpInfo->iCtrlId);
  212. if (nHelpID != 0)
  213. {
  214. if (nHelpID != -1)
  215. AfxGetApp()->WinHelp(nHelpID, HELP_CONTEXTPOPUP);
  216. return TRUE;
  217. } // if: found the control in the list
  218. } // if: need help on a specific control
  219. // Display dialog help.
  220. return FALSE;
  221. } //*** CDialogHelp::OnHelpInfo()
  222. /////////////////////////////////////////////////////////////////////////////
  223. //++
  224. //
  225. // CDialogHelp::OnCommandHelp
  226. //
  227. // Routine Description:
  228. // Handler for the WM_COMMANDHELP message.
  229. //
  230. // Arguments:
  231. // WPARAM [IN] Passed on to base class method.
  232. // lParam [IN] Help ID.
  233. //
  234. // Return Value:
  235. // TRUE Help processed.
  236. // FALSE Help not processed.
  237. //
  238. //--
  239. /////////////////////////////////////////////////////////////////////////////
  240. LRESULT CDialogHelp::OnCommandHelp(WPARAM wParam, LPARAM lParam)
  241. {
  242. if (m_nHelpID != 0)
  243. lParam = m_nHelpID;
  244. AfxGetApp()->WinHelp((DWORD)lParam, HELP_CONTEXTPOPUP);
  245. return TRUE;
  246. // return CDialog::OnCommandHelp(wParam, lParam);
  247. } //*** CDialogHelp::OnCommandHelp()