怎样调用.chm文件?(50分)

  • 主题发起人 主题发起人 netsong
  • 开始时间 开始时间
想知道是吧,有个控件,我也不知道从那下的了,只好浪费一点大家的时间把代码copy上来<br>有这些功能吧<br>Close help window <br>This button closes an open help window. <br><br>Show table of contents <br>If you click this button, it executes the command: <br>application.helpcommand(HELP_FINDER, 0); <br><br>Show default topic <br>This will display the default topic of your help file ("introduction" or so). If you click this button, it executes the command: <br>application.helpcommand(HELP_CONTENT, 0); <br><br>Display topic <br>Select a topic from the combo box left of the button. Then click to display the topic. <br>The button executes the command: <br>if Combobox1.text &lt;&gt; '' then HTMLhelpRouter1.HelpJump('', Combobox1.text); <br><br>Jump directly to a keyword <br><br>Enter a keyword in the edit box left of the button. Then click to jump directly to the keyword. If your keyword is not found, no topic is displayed. If the keyword occours in more than one topic (for example the keyword "keyword" in this help file), a list of topics is displayed. <br><br>The button executes the command: <br>HTMLhelpRouter1.HelpKLink(Edit2.text); <br><br>Jump to an A-keyword <br><br>Select an A-keyword in the combo box left of the button. Then click to jump directly to the A-keyword. If your A-keyword is not found, no topic is displayed. If the keyword occours in more than one topic , a list of topics is displayed. <br>HTMLhelpRouter1.HelpALink(Combobox2.text); <br><br>Display topic <br><br>Select a topic from the combo box left of the button. Then click to display the topic. <br>The button executes the command: <br><br>if Combobox1.text &lt;&gt; '' then HTMLhelpRouter1.HelpJump('', Combobox1.text); <br><br>Show default topic <br><br>This will display the default topic of your help file ("introduction" or so). If you click this button, it executes the command: <br><br>application.helpcommand(HELP_CONTENT, 0); <br><br>//*****************************<br>(*====================================================================<br>THTMLHelpRouter<br><br>Delphi 2/3/4 Implementation of HTML HELP<br><br>EMail: info@ec-software.com<br>Internet: http://www.ec-software.com<br><br>Disclaimer of Warranty<br>----------------------<br><br>THIS SOFTWARE AND THE ACCOMPANYING FILES ARE PROVIDED "AS IS" AND<br>WITHOUT WARRANTIES OF ANY KIND WHETHER EXPRESSED OR IMPLIED.<br><br>In no event shall the author be held liable for any damages whatsoever,<br>including without limitation, damages for loss of business profits,<br>business interruption, loss of business information, or any other loss<br>arising from the use or inability to use &nbsp;the software.<br>====================================================================*)<br><br>unit HelpRouter;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; Menus;<br><br>const<br>&nbsp; &nbsp;HH_DISPLAY_TOPIC &nbsp; &nbsp; &nbsp; &nbsp;= $0000;<br>&nbsp; &nbsp;HH_HELP_FINDER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $0000; &nbsp;// WinHelp equivalent<br>&nbsp; &nbsp;HH_DISPLAY_TOC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $0001; &nbsp;// not currently implemented<br>&nbsp; &nbsp;HH_DISPLAY_INDEX &nbsp; &nbsp; &nbsp; &nbsp;= $0002; &nbsp;// not currently implemented<br>&nbsp; &nbsp;HH_DISPLAY_SEARCH &nbsp; &nbsp; &nbsp; = $0003; &nbsp;// not currently implemented<br>&nbsp; &nbsp;HH_SET_WIN_TYPE &nbsp; &nbsp; &nbsp; &nbsp; = $0004;<br>&nbsp; &nbsp;HH_GET_WIN_TYPE &nbsp; &nbsp; &nbsp; &nbsp; = $0005;<br>&nbsp; &nbsp;HH_GET_WIN_HANDLE &nbsp; &nbsp; &nbsp; = $0006;<br>&nbsp; &nbsp;HH_ENUM_INFO_TYPE &nbsp; &nbsp; &nbsp; = $0007;<br>&nbsp; &nbsp;HH_SET_INFO_TYPE &nbsp; &nbsp; &nbsp; &nbsp;= $0008;<br>&nbsp; &nbsp;HH_SYNC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $0009;<br>&nbsp; &nbsp;HH_RESERVED1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $000A;<br>&nbsp; &nbsp;HH_RESERVED2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $000B;<br>&nbsp; &nbsp;HH_RESERVED3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $000C;<br>&nbsp; &nbsp;HH_KEYWORD_LOOKUP &nbsp; &nbsp; &nbsp; = $000D;<br>&nbsp; &nbsp;HH_DISPLAY_TEXT_POPUP &nbsp; = $000E;<br>&nbsp; &nbsp;HH_HELP_CONTEXT &nbsp; &nbsp; &nbsp; &nbsp; = $000F;<br>&nbsp; &nbsp;HH_TP_HELP_CONTEXTMENU &nbsp;= $0010;<br>&nbsp; &nbsp;HH_TP_HELP_WM_HELP &nbsp; &nbsp; &nbsp;= $0011;<br>&nbsp; &nbsp;HH_CLOSE_ALL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $0012;<br>&nbsp; &nbsp;HH_ALINK_LOOKUP &nbsp; &nbsp; &nbsp; &nbsp; = $0013;<br>&nbsp; &nbsp;HH_GET_LAST_ERROR &nbsp; &nbsp; &nbsp; = $0014;<br>&nbsp; &nbsp;HH_ENUM_CATEGORY &nbsp; &nbsp; &nbsp; &nbsp;= $0015;<br>&nbsp; &nbsp;HH_ENUM_CATEGORY_IT &nbsp; &nbsp; = $0016;<br>&nbsp; &nbsp;HH_RESET_IT_FILTER &nbsp; &nbsp; &nbsp;= $0017;<br>&nbsp; &nbsp;HH_SET_INCLUSIVE_FILTER = $0018;<br>&nbsp; &nbsp;HH_SET_EXCLUSIVE_FILTER = $0019;<br>&nbsp; &nbsp;HH_INITIALIZE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $001C;<br>&nbsp; &nbsp;HH_UNINITIALIZE &nbsp; &nbsp; &nbsp; &nbsp; = $001D;<br>&nbsp; &nbsp;HH_PRETRANSLATEMESSAGE &nbsp;= $00fd;<br>&nbsp; &nbsp;HH_SET_GLOBAL_PROPERTY &nbsp;= $00fc;<br><br>type<br>&nbsp; &nbsp;THH_POPUP = record<br>&nbsp; &nbsp; &nbsp; cbStruct: integer;<br>&nbsp; &nbsp; &nbsp; hinst: THandle;<br>&nbsp; &nbsp; &nbsp; idString: cardinal;<br>&nbsp; &nbsp; &nbsp; pszText: PChar;<br>&nbsp; &nbsp; &nbsp; pt: TPoint;<br>&nbsp; &nbsp; &nbsp; clrForeground: TColor;<br>&nbsp; &nbsp; &nbsp; clrBackground: TColor;<br>&nbsp; &nbsp; &nbsp; rcMargins: TRect;<br>&nbsp; &nbsp; &nbsp; pszFont: PChar;<br>&nbsp; &nbsp;end;<br><br>type<br>&nbsp; &nbsp;THH_AKLINK = record<br>&nbsp; &nbsp; &nbsp; cbStruct: integer;<br>&nbsp; &nbsp; &nbsp; fReserved: boolean;<br>&nbsp; &nbsp; &nbsp; pszKeywords: Pchar;<br>&nbsp; &nbsp; &nbsp; pszUrl: Pchar;<br>&nbsp; &nbsp; &nbsp; pszMsgText: PChar;<br>&nbsp; &nbsp; &nbsp; pszMsgTitle: PChar;<br>&nbsp; &nbsp; &nbsp; pszMsgWindow: PChar;<br>&nbsp; &nbsp; &nbsp; fIndexOnFail: boolean;<br>&nbsp; &nbsp;end;<br><br>type<br>&nbsp; THelpType = (htAuto, htWinhelp, htHTMLhelp);<br><br>&nbsp; EOwnerError = class(Exception);<br><br>&nbsp; THTMLhelpRouter = class(TComponent)<br>&nbsp; private<br>&nbsp; &nbsp; fHelpType: THelpType;<br>&nbsp; &nbsp; fAppOnHelp: THelpEvent;<br>&nbsp; &nbsp; function &nbsp;CurrentForm: TForm;<br>&nbsp; &nbsp; function &nbsp;OnRouteHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;<br>&nbsp; &nbsp; function &nbsp;FindHandle(var Helphandle: HWND; var Helpfile: string): boolean;<br>&nbsp; &nbsp; procedure SetHelpType(value: THelpType);<br>&nbsp; protected<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; destructor &nbsp;Destroy; override;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HTMLhelpInstalled: boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpContent: boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpKeyword(keyword: string): boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpKLink(keyword: string): boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpALink(akeyword: string): boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpJump(helpfile, topicid: string): boolean;<br>&nbsp; &nbsp; function &nbsp; &nbsp;HelpPopup(X,Y: integer; text: string): boolean;<br>&nbsp; published<br>&nbsp; &nbsp; property HelpType: THelpType read fHelpType write SetHelpType;<br>&nbsp; end;<br><br>type<br>&nbsp; &nbsp;THtmlHelpA = function(hwndCaller: THandle; pszFile: PChar; uCommand: cardinal; dwData: longint): THandle; stdCall;<br><br>var<br>&nbsp; &nbsp;HtmlHelpA: THtmlHelpA;<br>&nbsp; &nbsp;HHCTRL: THandle;<br>&nbsp; &nbsp;GLOBAL_HELPROUTER: THTMLhelpRouter;<br><br>procedure Register;<br><br>implementation<br><br>function LoadHHCTRL: boolean;<br>begin<br>&nbsp; if HHCTRL = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; HtmlHelpA := nil;<br>&nbsp; &nbsp; HHCTRL := LoadLibrary('HHCTRL.OCX');<br>&nbsp; &nbsp; if (HHCTRL &lt;&gt; 0) then HtmlHelpA := GetProcAddress(HHCTRL, 'HtmlHelpA');<br>&nbsp; end;<br>&nbsp; result := HHCTRL &lt;&gt; 0;<br>end;<br><br>function CheckRouterInstance: boolean;<br>begin<br>&nbsp; result := false;<br>&nbsp; if GLOBAL_HELPROUTER &lt;&gt; NIL then raise Exception.Create('Multiple instances of THTMLhelpRouter are not allowed')<br>&nbsp; else result := true;<br>end;<br><br>{ --- THTMLhelpRouter --- }<br><br>constructor THTMLhelpRouter.Create(AOwner: TComponent);<br>begin<br>&nbsp; inherited Create(AOwner);<br>&nbsp; if CheckRouterInstance then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;fAppOnHelp := Application.onhelp;<br>&nbsp; &nbsp; &nbsp; &nbsp;Application.onhelp := OnRouteHelp;<br>&nbsp; &nbsp; &nbsp; &nbsp;GLOBAL_HELPROUTER := Self;<br>&nbsp; end;<br>end;<br><br>destructor THTMLhelpRouter.Destroy;<br>begin<br>&nbsp; if assigned(fAppOnHelp) then Application.onhelp := fAppOnHelp;<br>&nbsp; GLOBAL_HELPROUTER := nil;<br>&nbsp; inherited Destroy;<br>end;<br><br>function THTMLhelpRouter.CurrentForm: TForm;<br>begin<br>&nbsp; if Screen.ActiveForm &lt;&gt; NIL then<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:= Screen.ActiveForm<br>&nbsp; else Result:= Owner as TForm;<br>end;<br><br>procedure THTMLhelpRouter.SetHelpType(value: THelpType);<br>begin<br>&nbsp; &nbsp; &nbsp;if value &lt;&gt; fHelpType then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fHelpType := value;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if fHelpType in [htAuto,htHTMLhelp] then LoadHHCTRL;<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br><br>function THTMLhelpRouter.HTMLhelpInstalled: boolean;<br>begin<br>&nbsp; if HHCTRL = 0 then LoadHHCTRL;<br>&nbsp; result := assigned(HtmlHelpA);<br>end;<br><br>function THTMLhelpRouter.FindHandle(var Helphandle: HWND; var Helpfile: string): boolean;<br>var<br>&nbsp; &nbsp;CForm: TForm;<br>begin<br>&nbsp; &nbsp;case HelpType of<br>&nbsp; &nbsp; &nbsp; htWinhelp: &nbsp;result := false;<br>&nbsp; &nbsp; &nbsp; htHTMLhelp: result := true;<br>&nbsp; &nbsp; &nbsp; htAuto: &nbsp; &nbsp; result := HTMLhelpInstalled;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;HelpFile := Application.helpfile;<br>&nbsp; &nbsp;HelpHandle := Application.handle;<br>{IFDEF VER100}<br>&nbsp; &nbsp;CForm := CurrentForm;<br>&nbsp; &nbsp;if Assigned(CForm) and CForm.HandleAllocated and (CForm.HelpFile &lt;&gt; '') then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;HelpHandle := CForm.Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp;HelpFile := CForm.HelpFile;<br>&nbsp; &nbsp;end;<br>{ENDIF}<br>end;<br><br>function THTMLhelpRouter.OnRouteHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;<br>var<br>&nbsp; &nbsp;showHTML: boolean;<br>&nbsp; &nbsp;rHandle: integer;<br>&nbsp; &nbsp;HelpHandle: HWND;<br>&nbsp; &nbsp;HelpFile: string;<br>// &nbsp; IDS: array[0..2] of DWORD;<br>begin<br>&nbsp; &nbsp;if assigned(fAppOnHelp) then result := fAppOnHelp(command, data, callhelp);<br>&nbsp; &nbsp;if not callHelp then exit;<br><br>&nbsp; &nbsp;showHTML := FindHandle(HelpHandle, HelpFile);<br>&nbsp; &nbsp;result := false;<br>&nbsp; &nbsp;if showHTML then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;rHandle := 0;<br>&nbsp; &nbsp; &nbsp;HelpFile := changefileext(Helpfile,'.chm');<br>&nbsp; &nbsp; &nbsp;case Command of<br>&nbsp; &nbsp; &nbsp;HELP_FINDER, HELP_CONTENTS: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOC, 0); &nbsp;//show table of contents<br>&nbsp; &nbsp; &nbsp;HELP_KEY: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_INDEX, data); &nbsp;//display keywordshow table of contens<br>&nbsp; &nbsp; &nbsp;HELP_QUIT: rHandle := HtmlHelpA(helphandle, nil, HH_CLOSE_ALL, 0);<br>&nbsp; &nbsp; &nbsp;HELP_CONTEXT: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_HELP_CONTEXT, data); &nbsp;//display help context<br>&nbsp; &nbsp; &nbsp;HELP_CONTEXTPOPUP: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_HELP_CONTEXT, data);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;Result := rHandle &lt;&gt; 0;<br>&nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;if (not result) and (fHelpType &lt;&gt; htHTMLhelp) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Result := WinHelp(HelpHandle, PChar(changefileext(HelpFile,'.hlp')), Command, Data);<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;CallHelp := false;<br>end;<br><br>function THTMLhelpRouter.HelpContent: boolean;<br>begin<br>&nbsp; &nbsp;result := application.helpcommand(HELP_FINDER, 0);<br>end;<br><br>function THTMLhelpRouter.HelpJump(helpfile, topicid: string): boolean;<br>var<br>&nbsp; &nbsp;Command: array[0..255] of Char;<br>&nbsp; &nbsp;showHTML: boolean;<br>&nbsp; &nbsp;rHandle: integer;<br>&nbsp; &nbsp;HelpHandle: HWND;<br>&nbsp; &nbsp;HFile, HID: string;<br>&nbsp; &nbsp;CForm: TForm;<br>begin<br>&nbsp; &nbsp;result := false;<br>&nbsp; &nbsp;showHTML := FindHandle(HelpHandle, HFile);<br><br>&nbsp; &nbsp;if Helpfile &lt;&gt; '' then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; HFile := HelpFile;<br>&nbsp; &nbsp; &nbsp; &nbsp; HelpHandle := 0;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;if showHTML then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;rHandle := 0;<br>&nbsp; &nbsp; &nbsp;HelpFile := changefileext(HFile,'.chm');<br>&nbsp; &nbsp; &nbsp;HID := TopicID;<br>&nbsp; &nbsp; &nbsp;if copy(lowercase(extractfileext(HID)),1,4) &lt;&gt; '.htm' then HID := HID + '.htm';<br>&nbsp; &nbsp; &nbsp;rHandle := HtmlHelpA(helphandle, pchar(Helpfile+'::/'+HID), HH_DISPLAY_TOPIC, 0); &nbsp;//show table of contents<br>&nbsp; &nbsp; &nbsp;Result := rHandle &lt;&gt; 0;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;if (not result) and (fHelpType &lt;&gt; htHTMLhelp) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;helpfile := changefileext(HFile,'.hlp');<br>&nbsp; &nbsp; &nbsp;StrLFmt(Command, SizeOf(Command) - 1, 'JumpID("","%s")', [TopicID]);<br>&nbsp; &nbsp; &nbsp;Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br>&nbsp; &nbsp; &nbsp;if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br>&nbsp; &nbsp;end;<br>end;<br><br>function THTMLhelpRouter.HelpPopup(X,Y: integer; text: string): boolean;<br>var<br>&nbsp; &nbsp;CForm: TForm;<br>&nbsp; &nbsp;HP: THH_Popup;<br>begin<br>&nbsp; &nbsp;if (fHelpType &lt;&gt; htWinhelp) and HTMLhelpInstalled then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;CForm := CurrentForm;<br>&nbsp; &nbsp; &nbsp;with HP do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbStruct := sizeof(HP);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInstance := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idString := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszText := PChar(text);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pt.x := X;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pt.y := Y;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ClientToScreen(CForm.handle, pt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clrForeground := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clrBackground := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rcMargins.Left := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rcMargins.Right := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rcMargins.Top := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rcMargins.Bottom := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszFont := PChar('MS Sans Serif, 10');<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;result := HtmlHelpA(CForm.handle, nil, HH_DISPLAY_TEXT_POPUP, longint(@HP)) &lt;&gt; 0;<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else result := false;<br>end;<br><br>function THTMLhelpRouter.HelpKeyword(keyword: string): boolean;<br>var<br>&nbsp; Command: array[0..255] of Char;<br>begin<br>&nbsp; StrLcopy(Command, pchar(keyword), SizeOf(Command) - 1);<br>&nbsp; result := application.helpcommand(HELP_KEY, Longint(@Command));<br>end;<br><br>function THTMLhelpRouter.HelpKLink(keyword: string): boolean;<br>var<br>&nbsp; &nbsp;Command: array[0..255] of Char;<br>&nbsp; &nbsp;showHTML: boolean;<br>&nbsp; &nbsp;rHandle: integer;<br>&nbsp; &nbsp;HelpHandle: HWND;<br>&nbsp; &nbsp;HFile, Helpfile: string;<br>&nbsp; &nbsp;CForm: TForm;<br>&nbsp; &nbsp;HA: THH_AKLINK;<br>begin<br>&nbsp; &nbsp;result := false;<br>&nbsp; &nbsp;showHTML := FindHandle(HelpHandle, HFile);<br><br>&nbsp; &nbsp;if showHTML then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;rHandle := 0;<br>&nbsp; &nbsp; &nbsp;HelpFile := changefileext(HFile,'.chm');<br><br>&nbsp; &nbsp; &nbsp;with HA do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbStruct := sizeof(HA);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fReserved := false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszKeywords := pchar(keyword);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszUrl := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgText := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgTitle := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgWindow := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fIndexOnFail := true;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOPIC, 0); &nbsp;//create window<br>&nbsp; &nbsp; &nbsp;if rHandle &lt;&gt; 0 then rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_KEYWORD_LOOKUP, longint(@HA));<br>&nbsp; &nbsp; &nbsp;Result := rHandle &lt;&gt; 0;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;if (not result) and (fHelpType &lt;&gt; htHTMLhelp) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;helpfile := changefileext(HFile,'.hlp');<br>&nbsp; &nbsp; &nbsp;StrLFmt(Command, SizeOf(Command) - 1, 'KL("%s",1)', [keyword]);<br>&nbsp; &nbsp; &nbsp;Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br>&nbsp; &nbsp; &nbsp;if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br>&nbsp; &nbsp;end;<br>end;<br><br>function THTMLhelpRouter.HelpALink(akeyword: string): boolean;<br>var<br>&nbsp; &nbsp;Command: array[0..255] of Char;<br>&nbsp; &nbsp;showHTML: boolean;<br>&nbsp; &nbsp;rHandle: integer;<br>&nbsp; &nbsp;HelpHandle: HWND;<br>&nbsp; &nbsp;HFile, Helpfile: string;<br>&nbsp; &nbsp;CForm: TForm;<br>&nbsp; &nbsp;HA: THH_AKLINK;<br>begin<br>&nbsp; &nbsp;result := false;<br>&nbsp; &nbsp;showHTML := FindHandle(HelpHandle, HFile);<br><br>&nbsp; &nbsp;if showHTML then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;rHandle := 0;<br>&nbsp; &nbsp; &nbsp;HelpFile := changefileext(HFile,'.chm');<br><br>&nbsp; &nbsp; &nbsp;with HA do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbStruct := sizeof(HA);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fReserved := false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszKeywords := pchar(akeyword);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszUrl := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgText := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgTitle := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pszMsgWindow := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fIndexOnFail := true;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOPIC, 0); &nbsp;//create window<br>&nbsp; &nbsp; &nbsp;if rHandle &lt;&gt; 0 then rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_ALINK_LOOKUP, longint(@HA));<br>&nbsp; &nbsp; &nbsp;Result := rHandle &lt;&gt; 0;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;if (not result) and (fHelpType &lt;&gt; htHTMLhelp) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;helpfile := changefileext(HFile,'.hlp');<br>&nbsp; &nbsp; &nbsp;StrLFmt(Command, SizeOf(Command) - 1, 'AL("%s",1)', [akeyword]);<br>&nbsp; &nbsp; &nbsp;Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br>&nbsp; &nbsp; &nbsp;if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br>&nbsp; &nbsp;end;<br>end;<br><br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('EC', [THTMLhelpRouter]);<br>end;<br><br>initialization<br>&nbsp; HHCTRL := 0;<br><br>finalization<br>&nbsp; &nbsp;if (HHCTRL &lt;&gt; 0) then FreeLibrary(HHCTRL);<br>end.<br>//*****************
 
多人接受答案了。
 
后退
顶部