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.

275 lines
7.5 KiB

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