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.

216 lines
5.5 KiB

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