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.

303 lines
8.1 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Help support.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "main.h"
  9. #include <htmlhelp.h>
  10. #include "cerhelp.h"
  11. //#include "cmnutil.hpp"
  12. //#include "dhhelp.h"
  13. TCHAR g_HelpFileName[MAX_PATH];
  14. void
  15. MakeHelpFileName()
  16. {
  17. TCHAR *Tmp = NULL;
  18. //
  19. // Get the file name for the base module.
  20. //
  21. if (GetModuleFileName(GetModuleHandle(NULL), g_HelpFileName,
  22. sizeof g_HelpFileName / sizeof g_HelpFileName[0]))
  23. {
  24. // Remove the executable name.
  25. Tmp = g_HelpFileName + _tcslen(g_HelpFileName);
  26. if (Tmp != g_HelpFileName)
  27. {
  28. --Tmp;
  29. }
  30. while ( (*Tmp != NULL) && (*Tmp != _T('\\')) && Tmp != g_HelpFileName)
  31. {
  32. --Tmp;
  33. }
  34. }
  35. if ( (Tmp == NULL) || (Tmp == g_HelpFileName))
  36. {
  37. // Error. Use the current directory.
  38. Tmp = g_HelpFileName;
  39. *Tmp++ = _T('.');
  40. }
  41. *Tmp = 0;
  42. if (StringCbCat(g_HelpFileName,sizeof g_HelpFileName, _T("\\")) != S_OK)
  43. {
  44. goto ERRORS;
  45. }
  46. //CatString(g_HelpFileName, "\\", DIMA(g_HelpFileName));
  47. //CatString(g_HelpFileName, File, DIMA(g_HelpFileName));
  48. if( StringCbCat(g_HelpFileName,sizeof g_HelpFileName, _T("CerHelp.chm")) != S_OK)
  49. {
  50. goto ERRORS;
  51. }
  52. ERRORS:
  53. ;
  54. }
  55. /*** OpenHelpTopic - opens the .chm and selects the specified topic
  56. *
  57. * Purpose:
  58. * This opens the Help File and displays the specified page.
  59. * (This help file's name is stored as g_HelpFileName, but
  60. * this string will presumably always be "debugger.chm".)
  61. * If the .chm has already been opened for context-sensitive
  62. * help, the already-existing .chm will be used.
  63. *
  64. * This function should be called when you know exactly what
  65. * page is needed -- for instance, if a "Help" button is pressed.
  66. *
  67. * Input:
  68. * PageConstant -- this is one of the topic constants defined
  69. * in the header file generated when the .chm
  70. * is built -- these constants will always
  71. * be of the form "help_topic_xxxxx"
  72. *
  73. * Returns:
  74. * 0 - debugger.chm opened and page displayed correctly
  75. * 1 - debugger.chm opened, but specified page not found
  76. * 2 - debugger.chm not opened (probably the file wasn't found)
  77. *
  78. * Exceptions:
  79. * None
  80. *
  81. *************************************************************************/
  82. ULONG
  83. OpenHelpTopic(ULONG PageConstant)
  84. {
  85. HWND helpfileHwnd;
  86. HWND returnedHwnd;
  87. // If we knew we were in WinDbg, we could use WinDbg's HWND,
  88. // but we could be in a console debugger.
  89. helpfileHwnd = GetDesktopWindow();
  90. // Make "Contents" the active panel in debugger.chm
  91. returnedHwnd =
  92. HtmlHelp(helpfileHwnd,
  93. g_HelpFileName,
  94. HH_DISPLAY_TOC,
  95. 0);
  96. if (returnedHwnd == NULL)
  97. {
  98. return HELP_FAILURE;
  99. }
  100. // Select the proper page
  101. /* returnedHwnd =
  102. HtmlHelp(helpfileHwnd,
  103. g_HelpFileName,
  104. HH_HELP_CONTEXT,
  105. PageConstant);
  106. if (returnedHwnd == NULL)
  107. {
  108. return HELP_NO_SUCH_PAGE;
  109. }
  110. */
  111. return HELP_SUCCESS;
  112. }
  113. /*** OpenHelpIndex - opens the .chm and searches for the specified text
  114. *
  115. * Purpose:
  116. * This opens the Help File and looks up the specified text in
  117. * the Index. (This help file's name is stored as g_HelpFileName,
  118. * but this string will presumably always be "debugger.chm".)
  119. * If the .chm has already been opened for context-sensitive
  120. * help, the already-existing .chm will be used.
  121. *
  122. * This function should be called when you don't know exactly
  123. * which page is needed -- for instance, if someone types
  124. * "help bp" or "help breakpoints" in the Command window.
  125. *
  126. * Input:
  127. * IndexText -- any text string (even ""); this string will
  128. * appear in the Index panel of the .chm
  129. *
  130. * Returns:
  131. * 0 - debugger.chm opened and index search displayed correctly
  132. * 2 - debugger.chm not opened (probably the file wasn't found)
  133. *
  134. * Exceptions:
  135. * None
  136. *
  137. *************************************************************************/
  138. ULONG
  139. OpenHelpIndex(PCSTR IndexText)
  140. {
  141. HWND helpfileHwnd;
  142. HWND returnedHwnd;
  143. // If we knew we were in WinDbg, we could use WinDbg's HWND,
  144. // but we could be in a console debugger.
  145. helpfileHwnd = GetDesktopWindow();
  146. // Select the Index panel and clip IndexText into it.
  147. returnedHwnd =
  148. HtmlHelp(helpfileHwnd,
  149. g_HelpFileName,
  150. HH_DISPLAY_INDEX,
  151. (DWORD_PTR)IndexText);
  152. if (returnedHwnd == NULL)
  153. {
  154. return HELP_FAILURE;
  155. }
  156. return HELP_SUCCESS;
  157. }
  158. ULONG
  159. OpenHelpSearch(PCSTR SearchText)
  160. {
  161. HWND helpfileHwnd;
  162. HWND returnedHwnd;
  163. HH_FTS_QUERY Query;
  164. // If we knew we were in WinDbg, we could use WinDbg's HWND,
  165. // but we could be in a console debugger.
  166. helpfileHwnd = GetDesktopWindow();
  167. // Select the Search panel.
  168. ZeroMemory(&Query, sizeof(Query));
  169. Query.cbStruct = sizeof(Query);
  170. Query.pszSearchQuery = SearchText;
  171. returnedHwnd =
  172. HtmlHelp(helpfileHwnd,
  173. g_HelpFileName,
  174. HH_DISPLAY_SEARCH,
  175. (DWORD_PTR)&Query);
  176. if (returnedHwnd == NULL)
  177. {
  178. return HELP_FAILURE;
  179. }
  180. return HELP_SUCCESS;
  181. }
  182. ULONG
  183. OpenHelpKeyword(PCSTR Keyword, BOOL ShowErrorPopup)
  184. {
  185. HWND helpfileHwnd;
  186. HWND returnedHwnd;
  187. HH_AKLINK helpfileLink;
  188. helpfileLink.cbStruct = sizeof(helpfileLink);
  189. helpfileLink.fReserved = FALSE;
  190. helpfileLink.pszKeywords = Keyword;
  191. helpfileLink.pszUrl = NULL;
  192. // If ShowErrorPopup is TRUE, then entering an invalid keyword will cause
  193. // an error message to be displayed. If FALSE, it will cause the .chm to
  194. // display the Index tab, and the keyword will be entered into the index
  195. // box, just as with OpenHelpIndex.
  196. if (ShowErrorPopup)
  197. {
  198. helpfileLink.pszMsgText =
  199. "The text you entered is not in the index of this help file.";
  200. helpfileLink.pszMsgTitle = "HTML Help Error";
  201. helpfileLink.pszWindow = NULL;
  202. helpfileLink.fIndexOnFail = FALSE;
  203. }
  204. else
  205. {
  206. helpfileLink.pszMsgText = NULL;
  207. helpfileLink.pszMsgTitle = NULL;
  208. helpfileLink.pszWindow = NULL;
  209. helpfileLink.fIndexOnFail = TRUE;
  210. }
  211. // If we knew we were in WinDbg, we could use WinDbg's HWND,
  212. // but we could be in a console debugger.
  213. helpfileHwnd = GetDesktopWindow();
  214. // Select the Index panel and clip IndexText into it.
  215. returnedHwnd =
  216. HtmlHelp(helpfileHwnd,
  217. g_HelpFileName,
  218. HH_KEYWORD_LOOKUP,
  219. (DWORD_PTR)&helpfileLink);
  220. if (returnedHwnd == NULL)
  221. {
  222. return HELP_NO_SUCH_PAGE;
  223. }
  224. return HELP_SUCCESS;
  225. }
  226. BOOL
  227. SpawnHelp(ULONG Topic)
  228. {
  229. CHAR StartHelpCommand[MAX_PATH + 32];
  230. PROCESS_INFORMATION ProcInfo = {0};
  231. STARTUPINFO SI = {0};
  232. // Start help with the given arguments.
  233. if(StringCbPrintf(StartHelpCommand, sizeof StartHelpCommand,_T("hh.exe -mapid %d "), Topic) != S_OK)
  234. {
  235. goto ERRORS;
  236. }
  237. // CatString(StartHelpCommand, g_HelpFileName, DIMA(StartHelpCommand));
  238. if(StringCbCat(StartHelpCommand, sizeof StartHelpCommand, g_HelpFileName) != S_OK)
  239. {
  240. goto ERRORS;
  241. }
  242. return CreateProcess(NULL,
  243. StartHelpCommand,
  244. NULL,
  245. NULL,
  246. FALSE,
  247. CREATE_BREAKAWAY_FROM_JOB,
  248. NULL,
  249. NULL,
  250. &SI,
  251. &ProcInfo);
  252. ERRORS:
  253. return FALSE;
  254. }