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.

331 lines
7.5 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlPopusHelp.h
  7. //
  8. // Implementation File:
  9. // None.
  10. //
  11. // Description:
  12. // Definition of the CPopusHelp
  13. //
  14. // Author:
  15. // Galen Barbee (galenb) May 18, 1998
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef __ATLPOPUPHELP_H_
  23. #define __ATLPOPUPHELP_H_
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Forward Class Declarations
  26. /////////////////////////////////////////////////////////////////////////////
  27. struct CMapCtrlToHelpID;
  28. template < class T > class CPopupHelp;
  29. /////////////////////////////////////////////////////////////////////////////
  30. // External Class Declarations
  31. /////////////////////////////////////////////////////////////////////////////
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Include Files
  34. /////////////////////////////////////////////////////////////////////////////
  35. #ifndef __ADMCOMMONRES_H_
  36. #include "AdmCommonRes.h"
  37. #endif // __ADMCOMMONRES_H_
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Type Definitions
  40. /////////////////////////////////////////////////////////////////////////////
  41. /////////////////////////////////////////////////////////////////////////////
  42. // struct CMapCtrlToHelpID
  43. /////////////////////////////////////////////////////////////////////////////
  44. struct CMapCtrlToHelpID
  45. {
  46. DWORD m_nCtrlID;
  47. DWORD m_nHelpCtrlID;
  48. }; //*** struct CMapCtrlToHelpID
  49. /////////////////////////////////////////////////////////////////////////////
  50. //++
  51. //
  52. // class CPopupHelp
  53. //
  54. // Description:
  55. // Provide popup-help functionality.
  56. //
  57. // Inheritance:
  58. // CPopupHelp
  59. //
  60. //--
  61. /////////////////////////////////////////////////////////////////////////////
  62. template < class T >
  63. class CPopupHelp
  64. {
  65. typedef CPopupHelp< T > thisClass;
  66. public:
  67. //
  68. // Construction
  69. //
  70. // Standard constructor
  71. CPopupHelp( void )
  72. {
  73. } //*** CPopupHelp()
  74. public:
  75. //
  76. // Message map.
  77. //
  78. BEGIN_MSG_MAP( thisclass )
  79. MESSAGE_HANDLER( WM_HELP, LrOnHelp )
  80. MESSAGE_HANDLER( WM_CONTEXTMENU, LrOnContextMenu )
  81. END_MSG_MAP()
  82. //
  83. // Message handler functions.
  84. //
  85. /////////////////////////////////////////////////////////////////////////////
  86. //++
  87. //
  88. // LrOnContextMenu
  89. //
  90. // Routine Description:
  91. // Message handler for WM_CONTEXTMENU
  92. //
  93. // Arguments:
  94. // uMsg [IN] Message (WM_CONTEXT)
  95. // wParam [IN] Window handle of the control being queried
  96. // lParam [IN] Pointer coordinates. LOWORD xPos, HIWORD yPos
  97. // bHandled [OUT]
  98. //
  99. // Return Value:
  100. //
  101. //
  102. //--
  103. /////////////////////////////////////////////////////////////////////////////
  104. LRESULT LrOnContextMenu(
  105. IN UINT uMsg,
  106. IN WPARAM wParam,
  107. IN LPARAM lParam,
  108. OUT BOOL & bHandled
  109. )
  110. {
  111. DWORD nHelpID = 0;
  112. DWORD nCtrlID = 0;
  113. CWindow cwnd( (HWND) wParam );
  114. WORD xPos = LOWORD( lParam );
  115. WORD yPos = HIWORD( lParam );
  116. //
  117. // Only display help if the window is visible.
  118. //
  119. if ( cwnd.GetStyle() & WS_VISIBLE )
  120. {
  121. nCtrlID = cwnd.GetDlgCtrlID();
  122. if ( nCtrlID != 0 )
  123. {
  124. nHelpID = NHelpFromCtrlID( nCtrlID, reinterpret_cast< const CMapCtrlToHelpID * >( T::PidHelpMap() ) );
  125. } // if: control has an ID
  126. } // if: over a child window
  127. //
  128. // Display a popup menu.
  129. //
  130. if ( ( nHelpID != 0 ) && ( nHelpID != -1 ) )
  131. {
  132. bHandled = BContextMenu( cwnd, nHelpID, xPos, yPos );
  133. } // if: over a child window of this dialog with a tabstop
  134. return 1L;
  135. } //*** LrOnContextMenu()
  136. /////////////////////////////////////////////////////////////////////////////
  137. //++
  138. //
  139. // LrOnHelp
  140. //
  141. // Routine Description:
  142. // Message handler for WM_HELP.
  143. //
  144. // Arguments:
  145. // uMsg [IN] Message (WM_HELP)
  146. // wParam [IN]
  147. // lParam [IN] pointer to a HELPINFO struct
  148. // bHandled [OUT]
  149. //
  150. // Return Value:
  151. //
  152. //
  153. //--
  154. /////////////////////////////////////////////////////////////////////////////
  155. LRESULT LrOnHelp(
  156. IN UINT uMsg,
  157. IN WPARAM wParam,
  158. IN LPARAM lParam,
  159. OUT BOOL & bHandled
  160. )
  161. {
  162. LPHELPINFO phi = (LPHELPINFO) lParam;
  163. if ( phi->iContextType == HELPINFO_WINDOW )
  164. {
  165. DWORD nHelpID = 0;
  166. nHelpID = NHelpFromCtrlID( phi->iCtrlId & 0xFFFF, (const CMapCtrlToHelpID *) T::PidHelpMap() );
  167. if ( ( nHelpID != 0 ) && ( nHelpID != -1 ) )
  168. {
  169. T * pT = static_cast< T * >( this );
  170. CBaseApp * pbap = dynamic_cast< CBaseApp * >( &_Module );
  171. ATLASSERT( pbap != NULL );
  172. bHandled = pT->WinHelp( pbap->PszHelpFilePath(), HELP_CONTEXTPOPUP, nHelpID );
  173. }
  174. }
  175. return 1L;
  176. } //*** LrOnHelp()
  177. protected:
  178. /////////////////////////////////////////////////////////////////////////////
  179. //++
  180. //
  181. // NHelpFromCtrlID
  182. //
  183. // Routine Description:
  184. // Return the help ID from a control ID.
  185. //
  186. // Arguments:
  187. // nCtrlID [IN] ID of control to search for.
  188. //
  189. // Return Value:
  190. // nHelpID Help ID associated with the control.
  191. //
  192. //--
  193. /////////////////////////////////////////////////////////////////////////////
  194. DWORD NHelpFromCtrlID(
  195. IN DWORD nCtrlID,
  196. IN const CMapCtrlToHelpID * pMap
  197. ) const
  198. {
  199. ASSERT( pMap != NULL );
  200. ASSERT( nCtrlID != 0 );
  201. DWORD nHelpID = 0;
  202. for ( ; pMap->m_nCtrlID != 0 ; pMap++ )
  203. {
  204. if ( pMap->m_nCtrlID == nCtrlID )
  205. {
  206. nHelpID = pMap->m_nHelpCtrlID;
  207. break;
  208. } // if: found a match
  209. } // for: each control
  210. Trace( g_tagAlways, _T( "NHelpFromCtrlID() - nCtrlID = %x, nHelpID = %x" ), nCtrlID, nHelpID );
  211. return nHelpID;
  212. } //*** NHelpFromCtrlID()
  213. /////////////////////////////////////////////////////////////////////////////
  214. //++
  215. //
  216. // BContextMenu
  217. //
  218. // Routine Description:
  219. // Return the help ID from a control ID.
  220. //
  221. // Arguments:
  222. // cwnd [IN] - control's window
  223. // nHelpID [IN] - help context ID
  224. // xPos [IN] - xpos of the context menu
  225. // yPos [IN] - ypos of the context menu
  226. //
  227. // Return Value:
  228. // TRUE for success, FALSE for failure
  229. //
  230. //--
  231. /////////////////////////////////////////////////////////////////////////////
  232. BOOL BContextMenu(
  233. IN CWindow & cwnd,
  234. IN DWORD nHelpID,
  235. IN WORD xPos,
  236. IN WORD yPos
  237. )
  238. {
  239. CString strMenu;
  240. CMenu menu;
  241. BOOL bRet = FALSE;
  242. //
  243. // The context menu key was pressed. Get the current mouse position and use that
  244. //
  245. if ( ( xPos == 0xffff ) || ( yPos == 0xffff ) )
  246. {
  247. POINT pPos;
  248. if ( GetCursorPos( &pPos ) )
  249. {
  250. xPos = pPos.x;
  251. yPos = pPos.y;
  252. } // if: current cursor position retrieved successfully
  253. } // if: context menu key was pressed
  254. if ( strMenu.LoadString( ADMC_ID_MENU_WHATS_THIS ) )
  255. {
  256. if ( menu.CreatePopupMenu() )
  257. {
  258. if ( menu.AppendMenu( MF_STRING | MF_ENABLED, ADMC_ID_MENU_WHATS_THIS, strMenu ) )
  259. {
  260. DWORD nCmd;
  261. nCmd = menu.TrackPopupMenu(
  262. TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  263. xPos,
  264. yPos,
  265. cwnd
  266. );
  267. if ( nCmd != 0 )
  268. {
  269. CBaseApp * pbap = dynamic_cast< CBaseApp * >( &_Module );
  270. ATLASSERT( pbap != NULL );
  271. bRet = cwnd.WinHelp( pbap->PszHelpFilePath(), HELP_CONTEXTPOPUP, nHelpID );
  272. } // if: any command chosen
  273. else
  274. {
  275. Trace( g_tagError, _T( "OnContextMenu() - Last Error = %x" ), GetLastError() );
  276. } // else: unknown command
  277. } // if: menu item added successfully
  278. } // if: popup menu created successfully
  279. } // if: string could be loaded
  280. return bRet;
  281. } //*** BContextMenu()
  282. }; //*** class CPopupHelp
  283. /////////////////////////////////////////////////////////////////////////////
  284. #endif // __ATLPOPUPHELP_H_