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.

260 lines
5.2 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. // Globals to this module.
  4. BOOL bHelpActive = fFalse;
  5. //SZ szHelpFile = NULL;
  6. //DWORD dwLowContext = 0;
  7. //DWORD dwHighContext = 0;
  8. //DWORD dwHelpIndex = 0;
  9. //BOOL bHelpIsIndexed = fFalse;
  10. BOOL
  11. FInitWinHelpFile(
  12. HWND hWnd,
  13. SZ szHelpFileName,
  14. SZ szLowContext,
  15. SZ szHiContext,
  16. SZ szHelpIndex OPTIONAL
  17. )
  18. {
  19. //
  20. // Check the parameters
  21. //
  22. AssertRet ( hWnd != (HWND)NULL &&
  23. szHelpFileName != (SZ)NULL &&
  24. szLowContext != (SZ)NULL &&
  25. szHiContext != (SZ)NULL ,
  26. fFalse );
  27. //
  28. // Check if there is another help file active and close it
  29. //
  30. FCloseWinHelp(hWnd);
  31. //
  32. // Store the parameters passed in
  33. //
  34. pLocalContext()->dwLowContext = atoi ( szLowContext );
  35. pLocalContext()->dwHighContext = atoi ( szHiContext );
  36. if ( pLocalContext()->dwHighContext < pLocalContext()->dwLowContext ) {
  37. return ( fFalse );
  38. }
  39. while ((pLocalContext()->szHelpFile = SzDupl(szHelpFileName )) == (SZ)NULL) {
  40. if (!FHandleOOM(hWnd)) {
  41. return(fFalse);
  42. }
  43. }
  44. if ( szHelpIndex != (SZ)NULL ) {
  45. pLocalContext()->bHelpIsIndexed = fTrue;
  46. pLocalContext()->dwHelpIndex = atoi ( szHelpIndex );
  47. }
  48. else {
  49. pLocalContext()->bHelpIsIndexed = fFalse;
  50. }
  51. return ( fTrue );
  52. }
  53. BOOL
  54. FCloseWinHelp(
  55. HWND hWnd
  56. )
  57. {
  58. AssertRet ( hWnd != (HWND)NULL, fFalse );
  59. //
  60. // Find out if Help active and close the help file
  61. //
  62. if ( bHelpActive && pLocalContext()->szHelpFile != (SZ)NULL ) {
  63. WinHelp( hWnd, pLocalContext()->szHelpFile, HELP_QUIT, 0L );
  64. }
  65. bHelpActive = fFalse;
  66. //
  67. // Free the helpfile string and clear the bHelpIsIndexed field
  68. //
  69. if ( pLocalContext()->szHelpFile != (SZ) NULL ) {
  70. SFree( pLocalContext()->szHelpFile );
  71. pLocalContext()->szHelpFile = NULL;
  72. pLocalContext()->bHelpIsIndexed = fFalse;
  73. }
  74. return ( fTrue );
  75. }
  76. BOOL
  77. FProcessWinHelp(
  78. HWND hWnd
  79. )
  80. {
  81. SZ szHelpContext;
  82. DWORD dwHelpContext;
  83. AssertRet ( hWnd != (HWND)NULL, fFalse );
  84. //
  85. // Check if winhelp file available
  86. //
  87. if ( pLocalContext()->szHelpFile == (SZ)NULL ) {
  88. return ( fFalse );
  89. }
  90. //
  91. // Find the help context
  92. //
  93. if ((szHelpContext = SzFindSymbolValueInSymTab("HelpContext")) == (SZ)(NULL)) {
  94. return ( fFalse );
  95. }
  96. dwHelpContext = atoi ( szHelpContext );
  97. //
  98. // Validate it, see that it is within the two lo and hi contexts.
  99. //
  100. if ( dwHelpContext < pLocalContext()->dwLowContext ||
  101. dwHelpContext > pLocalContext()->dwHighContext ) {
  102. return ( fFalse );
  103. }
  104. //
  105. // Call Winhelp and set help active
  106. //
  107. bHelpActive = WinHelp(
  108. hWnd,
  109. pLocalContext()->szHelpFile,
  110. HELP_CONTEXT,
  111. dwHelpContext
  112. );
  113. if ( !bHelpActive ) {
  114. WinHelp( hWnd, pLocalContext()->szHelpFile, HELP_QUIT, 0L );
  115. return ( fFalse );
  116. }
  117. if ( pLocalContext()->bHelpIsIndexed == fTrue ) {
  118. WinHelp(
  119. hWnd,
  120. pLocalContext()->szHelpFile,
  121. HELP_SETINDEX,
  122. pLocalContext()->dwHelpIndex
  123. );
  124. }
  125. return ( fTrue );
  126. }
  127. BOOL
  128. FProcessWinHelpMenu(
  129. HWND hWnd,
  130. WORD idcMenu
  131. )
  132. {
  133. AssertRet ( hWnd != (HWND)NULL && idcMenu != 0, fFalse );
  134. //
  135. // Check if winhelp file available
  136. //
  137. if ( pLocalContext()->szHelpFile == (SZ)NULL ) {
  138. return ( fFalse );
  139. }
  140. switch ( idcMenu ) {
  141. case MENU_HELPINDEX:
  142. if ( pLocalContext()->bHelpIsIndexed == fTrue ) {
  143. bHelpActive = WinHelp(
  144. hWnd,
  145. pLocalContext()->szHelpFile,
  146. HELP_CONTEXT,
  147. pLocalContext()->dwHelpIndex
  148. );
  149. }
  150. else {
  151. bHelpActive = WinHelp(
  152. hWnd,
  153. pLocalContext()->szHelpFile,
  154. HELP_INDEX,
  155. 0
  156. );
  157. }
  158. break;
  159. case MENU_HELPSEARCH:
  160. bHelpActive = WinHelp(
  161. hWnd,
  162. pLocalContext()->szHelpFile,
  163. HELP_PARTIALKEY,
  164. (ULONG_PTR)""
  165. );
  166. break;
  167. case MENU_HELPONHELP:
  168. bHelpActive = WinHelp(
  169. hWnd,
  170. pLocalContext()->szHelpFile,
  171. HELP_HELPONHELP,
  172. 0
  173. );
  174. default:
  175. return ( fFalse );
  176. }
  177. if ( !bHelpActive ) {
  178. WinHelp( hWnd, pLocalContext()->szHelpFile, HELP_QUIT, 0L );
  179. return ( fFalse );
  180. }
  181. if ( pLocalContext()->bHelpIsIndexed == fTrue ) {
  182. WinHelp(
  183. hWnd,
  184. pLocalContext()->szHelpFile,
  185. HELP_SETINDEX,
  186. pLocalContext()->dwHelpIndex
  187. );
  188. }
  189. return ( fTrue );
  190. }