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.

279 lines
6.7 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 DWORD * pdwHelpMap, IN DWORD dwMask)
  56. {
  57. ASSERT(pdwHelpMap != NULL);
  58. CommonConstruct();
  59. SetMap(pdwHelpMap);
  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. m_dwMask = 0;
  82. m_nHelpID = 0;
  83. } //*** CDialogHelp::CommonConstruct()
  84. /////////////////////////////////////////////////////////////////////////////
  85. //++
  86. //
  87. // CDialogHelp::NHelpFromCtrlID
  88. //
  89. // Routine Description:
  90. // Return the help ID from a control ID.
  91. //
  92. // Arguments:
  93. // nCtrlID [IN] ID of control to search for.
  94. //
  95. // Return Value:
  96. // nHelpID Help ID associated with the control.
  97. //
  98. //--
  99. /////////////////////////////////////////////////////////////////////////////
  100. DWORD CDialogHelp::NHelpFromCtrlID(IN DWORD nCtrlID) const
  101. {
  102. DWORD nHelpID = 0;
  103. const CMapCtrlToHelpID * pmap = Pmap();
  104. ASSERT(pmap != NULL);
  105. ASSERT(nCtrlID != 0);
  106. for ( ; pmap->m_nCtrlID != 0 ; pmap++)
  107. {
  108. if (pmap->m_nCtrlID == nCtrlID)
  109. {
  110. nHelpID = pmap->m_nHelpCtrlID;
  111. break;
  112. } // if: found a match
  113. } // for: each control
  114. Trace(g_tagDlgHelp, _T("NHelpFromCtrlID() - nCtrlID = %x, nHelpID = %x"), nCtrlID, nHelpID);
  115. return nHelpID;
  116. } //*** CDialogHelp::NHelpFromCtrlID()
  117. /////////////////////////////////////////////////////////////////////////////
  118. //++
  119. //
  120. // CDialogHelp::OnContextMenu
  121. //
  122. // Routine Description:
  123. // Handler for the WM_CONTEXTMENU message.
  124. //
  125. // Arguments:
  126. // pWnd Window in which user clicked the right mouse button.
  127. // point Position of the cursor, in screen coordinates.
  128. //
  129. // Return Value:
  130. // TRUE Help processed.
  131. // FALSE Help not processed.
  132. //
  133. //--
  134. /////////////////////////////////////////////////////////////////////////////
  135. void CDialogHelp::OnContextMenu(CWnd * pWnd, CPoint point)
  136. {
  137. CWnd * pwndChild;
  138. CPoint ptDialog;
  139. DWORD nHelpID = 0;
  140. ASSERT(pWnd != NULL);
  141. m_nHelpID = 0;
  142. // Convert the point into dialog coordinates.
  143. ptDialog = point;
  144. pWnd->ScreenToClient(&ptDialog);
  145. // Find the control the cursor is over.
  146. {
  147. DWORD nCtrlID;
  148. pwndChild = pWnd->ChildWindowFromPoint(ptDialog);
  149. if ((pwndChild != NULL) && (pwndChild->GetStyle() & WS_VISIBLE))
  150. {
  151. nCtrlID = pwndChild->GetDlgCtrlID();
  152. if (nCtrlID != 0)
  153. nHelpID = NHelpFromCtrlID(nCtrlID);
  154. } // if: over a child window
  155. } // Find the control the cursor is over
  156. // Display a popup menu.
  157. if ((nHelpID != 0) && (nHelpID != -1))
  158. {
  159. CString strMenu;
  160. CMenu menu;
  161. try
  162. {
  163. strMenu.LoadString(IDS_MENU_WHATS_THIS);
  164. } // try
  165. catch (CMemoryException * pme)
  166. {
  167. pme->Delete();
  168. return;
  169. } // catch: CMemoryException
  170. if (menu.CreatePopupMenu())
  171. {
  172. if (menu.AppendMenu(MF_STRING | MF_ENABLED, ID_HELP, strMenu))
  173. {
  174. DWORD nCmd;
  175. m_nHelpID = nHelpID;
  176. nCmd = menu.TrackPopupMenu(
  177. TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  178. point.x,
  179. point.y,
  180. AfxGetMainWnd()
  181. );
  182. if (nCmd != 0)
  183. AfxGetApp()->WinHelp(m_nHelpID, HELP_CONTEXTPOPUP);
  184. } // if: menu item added successfully
  185. menu.DestroyMenu();
  186. } // if: popup menu created successfully
  187. } // if: over a child window of this dialog with a tabstop
  188. } //*** CDialogHelp::OnContextMenu()
  189. /////////////////////////////////////////////////////////////////////////////
  190. //++
  191. //
  192. // CDialogHelp::OnHelpInfo
  193. //
  194. // Routine Description:
  195. // Handler for the WM_HELPINFO message.
  196. //
  197. // Arguments:
  198. // pHelpInfo Structure containing info about displaying help.
  199. //
  200. // Return Value:
  201. // TRUE Help processed.
  202. // FALSE Help not processed.
  203. //
  204. //--
  205. /////////////////////////////////////////////////////////////////////////////
  206. BOOL CDialogHelp::OnHelpInfo(HELPINFO * pHelpInfo)
  207. {
  208. // If this is for a control, display control-specific help.
  209. if ((pHelpInfo->iContextType == HELPINFO_WINDOW)
  210. && (pHelpInfo->iCtrlId != 0))
  211. {
  212. DWORD nHelpID = NHelpFromCtrlID(pHelpInfo->iCtrlId);
  213. if (nHelpID != 0)
  214. {
  215. if (nHelpID != -1)
  216. AfxGetApp()->WinHelp(nHelpID, HELP_CONTEXTPOPUP);
  217. return TRUE;
  218. } // if: found the control in the list
  219. } // if: need help on a specific control
  220. // Display dialog help.
  221. return FALSE;
  222. } //*** CDialogHelp::OnHelpInfo()
  223. /////////////////////////////////////////////////////////////////////////////
  224. //++
  225. //
  226. // CDialogHelp::OnCommandHelp
  227. //
  228. // Routine Description:
  229. // Handler for the WM_COMMANDHELP message.
  230. //
  231. // Arguments:
  232. // WPARAM [IN] Passed on to base class method.
  233. // lParam [IN] Help ID.
  234. //
  235. // Return Value:
  236. // TRUE Help processed.
  237. // FALSE Help not processed.
  238. //
  239. //--
  240. /////////////////////////////////////////////////////////////////////////////
  241. LRESULT CDialogHelp::OnCommandHelp(WPARAM wParam, LPARAM lParam)
  242. {
  243. UNREFERENCED_PARAMETER( wParam );
  244. UNREFERENCED_PARAMETER( lParam );
  245. return TRUE;
  246. } //*** CDialogHelp::OnCommandHelp()