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.

274 lines
6.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-1999 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 "resource.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CDialogHelp class
  29. /////////////////////////////////////////////////////////////////////////////
  30. IMPLEMENT_DYNAMIC( CDialogHelp, CObject )
  31. /////////////////////////////////////////////////////////////////////////////
  32. //++
  33. //
  34. // CDialogHelp::CDialogHelp
  35. //
  36. // Routine Description:
  37. // Constructor.
  38. //
  39. // Arguments:
  40. // pmap [IN] Map array mapping control IDs to help IDs.
  41. // dwMask [IN] Mask to use for the low word of the help ID.
  42. //
  43. // Return Value:
  44. // None.
  45. //
  46. //--
  47. /////////////////////////////////////////////////////////////////////////////
  48. CDialogHelp::CDialogHelp( IN const DWORD * pdwHelpMap, IN DWORD dwMask )
  49. {
  50. ASSERT( pdwHelpMap != NULL );
  51. CommonConstruct();
  52. SetMap( pdwHelpMap );
  53. m_dwMask = dwMask;
  54. } //*** CDialogHelp::CDialogHelp()
  55. /////////////////////////////////////////////////////////////////////////////
  56. //++
  57. //
  58. // CDialogHelp::CommonConstruct
  59. //
  60. // Routine Description:
  61. // Do common construction.
  62. //
  63. // Arguments:
  64. // None.
  65. //
  66. // Return Value:
  67. // None.
  68. //
  69. //--
  70. /////////////////////////////////////////////////////////////////////////////
  71. void CDialogHelp::CommonConstruct( void )
  72. {
  73. m_pmap = NULL;
  74. m_dwMask = 0;
  75. m_nHelpID = 0;
  76. } //*** CDialogHelp::CommonConstruct()
  77. /////////////////////////////////////////////////////////////////////////////
  78. //++
  79. //
  80. // CDialogHelp::NHelpFromCtrlID
  81. //
  82. // Routine Description:
  83. // Return the help ID from a control ID.
  84. //
  85. // Arguments:
  86. // nCtrlID [IN] ID of control to search for.
  87. //
  88. // Return Value:
  89. // nHelpID Help ID associated with the control.
  90. //
  91. //--
  92. /////////////////////////////////////////////////////////////////////////////
  93. DWORD CDialogHelp::NHelpFromCtrlID( IN DWORD nCtrlID ) const
  94. {
  95. DWORD nHelpID = 0;
  96. const CMapCtrlToHelpID * pmap = Pmap();
  97. ASSERT( pmap != NULL );
  98. ASSERT( nCtrlID != 0 );
  99. for ( ; pmap->m_nCtrlID != 0 ; pmap++ )
  100. {
  101. if ( pmap->m_nCtrlID == nCtrlID )
  102. {
  103. nHelpID = pmap->m_nHelpCtrlID;
  104. break;
  105. } // if: found a match
  106. } // for: each control
  107. TRACE( _T("NHelpFromCtrlID() - nCtrlID = %x, nHelpID = %x"), nCtrlID, nHelpID );
  108. return nHelpID;
  109. } //*** CDialogHelp::NHelpFromCtrlID()
  110. /////////////////////////////////////////////////////////////////////////////
  111. //++
  112. //
  113. // CDialogHelp::OnContextMenu
  114. //
  115. // Routine Description:
  116. // Handler for the WM_CONTEXTMENU message.
  117. //
  118. // Arguments:
  119. // pWnd Window in which user clicked the right mouse button.
  120. // point Position of the cursor, in screen coordinates.
  121. //
  122. // Return Value:
  123. // TRUE Help processed.
  124. // FALSE Help not processed.
  125. //
  126. //--
  127. /////////////////////////////////////////////////////////////////////////////
  128. void CDialogHelp::OnContextMenu( CWnd * pWnd, CPoint point )
  129. {
  130. CWnd * pwndChild;
  131. CPoint ptDialog;
  132. DWORD nHelpID = 0;
  133. ASSERT( pWnd != NULL );
  134. m_nHelpID = 0;
  135. // Convert the point into dialog coordinates.
  136. ptDialog = point;
  137. pWnd->ScreenToClient( &ptDialog );
  138. // Find the control the cursor is over.
  139. {
  140. DWORD nCtrlID;
  141. pwndChild = pWnd->ChildWindowFromPoint( ptDialog );
  142. if ( ( pwndChild != NULL ) && ( pwndChild->GetStyle() & WS_VISIBLE ) )
  143. {
  144. nCtrlID = pwndChild->GetDlgCtrlID();
  145. if ( nCtrlID != 0 )
  146. {
  147. nHelpID = NHelpFromCtrlID( nCtrlID );
  148. } // if: control ID found
  149. } // if: over a child window
  150. } // Find the control the cursor is over
  151. // Display a popup menu.
  152. if ( ( nHelpID != 0 ) && ( nHelpID != -1 ) )
  153. {
  154. CString strMenu;
  155. CMenu menu;
  156. try
  157. {
  158. strMenu.LoadString( IDS_MENU_WHATS_THIS );
  159. } // try
  160. catch ( CMemoryException * pme )
  161. {
  162. pme->Delete();
  163. return;
  164. } // catch: CMemoryException
  165. if ( menu.CreatePopupMenu() )
  166. {
  167. if ( menu.AppendMenu( MF_STRING | MF_ENABLED, ID_HELP, strMenu ) )
  168. {
  169. DWORD nCmd;
  170. m_nHelpID = nHelpID;
  171. nCmd = menu.TrackPopupMenu(
  172. TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  173. point.x,
  174. point.y,
  175. AfxGetMainWnd()
  176. );
  177. if ( nCmd != 0 )
  178. {
  179. AfxGetApp()->WinHelp( m_nHelpID, HELP_CONTEXTPOPUP );
  180. } // if: menu item selected
  181. } // if: menu item added successfully
  182. menu.DestroyMenu();
  183. } // if: popup menu created successfully
  184. } // if: over a child window of this dialog with a tabstop
  185. } //*** CDialogHelp::OnContextMenu()
  186. /////////////////////////////////////////////////////////////////////////////
  187. //++
  188. //
  189. // CDialogHelp::OnHelpInfo
  190. //
  191. // Routine Description:
  192. // Handler for the WM_HELPINFO message.
  193. //
  194. // Arguments:
  195. // pHelpInfo Structure containing info about displaying help.
  196. //
  197. // Return Value:
  198. // TRUE Help processed.
  199. // FALSE Help not processed.
  200. //
  201. //--
  202. /////////////////////////////////////////////////////////////////////////////
  203. BOOL CDialogHelp::OnHelpInfo( HELPINFO * pHelpInfo )
  204. {
  205. // If this is for a control, display control-specific help.
  206. if ( ( pHelpInfo->iContextType == HELPINFO_WINDOW )
  207. && ( pHelpInfo->iCtrlId != 0 ) )
  208. {
  209. DWORD nHelpID = NHelpFromCtrlID( pHelpInfo->iCtrlId );
  210. if ( nHelpID != 0 )
  211. {
  212. if ( nHelpID != -1 )
  213. {
  214. AfxGetApp()->WinHelp( nHelpID, HELP_CONTEXTPOPUP );
  215. } // if: valid help ID found
  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. return TRUE;
  243. } //*** CDialogHelp::OnCommandHelp()