H
honghs
Unregistered / Unconfirmed
GUEST, unregistred user!
想知道是吧,有个控件,我也不知道从那下的了,只好浪费一点大家的时间把代码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 <> '' 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 <> '' 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 the software.<br>====================================================================*)<br><br>unit HelpRouter;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Menus;<br><br>const<br> HH_DISPLAY_TOPIC = $0000;<br> HH_HELP_FINDER = $0000; // WinHelp equivalent<br> HH_DISPLAY_TOC = $0001; // not currently implemented<br> HH_DISPLAY_INDEX = $0002; // not currently implemented<br> HH_DISPLAY_SEARCH = $0003; // not currently implemented<br> HH_SET_WIN_TYPE = $0004;<br> HH_GET_WIN_TYPE = $0005;<br> HH_GET_WIN_HANDLE = $0006;<br> HH_ENUM_INFO_TYPE = $0007;<br> HH_SET_INFO_TYPE = $0008;<br> HH_SYNC = $0009;<br> HH_RESERVED1 = $000A;<br> HH_RESERVED2 = $000B;<br> HH_RESERVED3 = $000C;<br> HH_KEYWORD_LOOKUP = $000D;<br> HH_DISPLAY_TEXT_POPUP = $000E;<br> HH_HELP_CONTEXT = $000F;<br> HH_TP_HELP_CONTEXTMENU = $0010;<br> HH_TP_HELP_WM_HELP = $0011;<br> HH_CLOSE_ALL = $0012;<br> HH_ALINK_LOOKUP = $0013;<br> HH_GET_LAST_ERROR = $0014;<br> HH_ENUM_CATEGORY = $0015;<br> HH_ENUM_CATEGORY_IT = $0016;<br> HH_RESET_IT_FILTER = $0017;<br> HH_SET_INCLUSIVE_FILTER = $0018;<br> HH_SET_EXCLUSIVE_FILTER = $0019;<br> HH_INITIALIZE = $001C;<br> HH_UNINITIALIZE = $001D;<br> HH_PRETRANSLATEMESSAGE = $00fd;<br> HH_SET_GLOBAL_PROPERTY = $00fc;<br><br>type<br> THH_POPUP = record<br> cbStruct: integer;<br> hinst: THandle;<br> idString: cardinal;<br> pszText: PChar;<br> pt: TPoint;<br> clrForeground: TColor;<br> clrBackground: TColor;<br> rcMargins: TRect;<br> pszFont: PChar;<br> end;<br><br>type<br> THH_AKLINK = record<br> cbStruct: integer;<br> fReserved: boolean;<br> pszKeywords: Pchar;<br> pszUrl: Pchar;<br> pszMsgText: PChar;<br> pszMsgTitle: PChar;<br> pszMsgWindow: PChar;<br> fIndexOnFail: boolean;<br> end;<br><br>type<br> THelpType = (htAuto, htWinhelp, htHTMLhelp);<br><br> EOwnerError = class(Exception);<br><br> THTMLhelpRouter = class(TComponent)<br> private<br> fHelpType: THelpType;<br> fAppOnHelp: THelpEvent;<br> function CurrentForm: TForm;<br> function OnRouteHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;<br> function FindHandle(var Helphandle: HWND; var Helpfile: string): boolean;<br> procedure SetHelpType(value: THelpType);<br> protected<br> public<br> constructor Create(AOwner: TComponent); override;<br> destructor Destroy; override;<br> function HTMLhelpInstalled: boolean;<br> function HelpContent: boolean;<br> function HelpKeyword(keyword: string): boolean;<br> function HelpKLink(keyword: string): boolean;<br> function HelpALink(akeyword: string): boolean;<br> function HelpJump(helpfile, topicid: string): boolean;<br> function HelpPopup(X,Y: integer; text: string): boolean;<br> published<br> property HelpType: THelpType read fHelpType write SetHelpType;<br> end;<br><br>type<br> THtmlHelpA = function(hwndCaller: THandle; pszFile: PChar; uCommand: cardinal; dwData: longint): THandle; stdCall;<br><br>var<br> HtmlHelpA: THtmlHelpA;<br> HHCTRL: THandle;<br> GLOBAL_HELPROUTER: THTMLhelpRouter;<br><br>procedure Register;<br><br>implementation<br><br>function LoadHHCTRL: boolean;<br>begin<br> if HHCTRL = 0 then<br> begin<br> HtmlHelpA := nil;<br> HHCTRL := LoadLibrary('HHCTRL.OCX');<br> if (HHCTRL <> 0) then HtmlHelpA := GetProcAddress(HHCTRL, 'HtmlHelpA');<br> end;<br> result := HHCTRL <> 0;<br>end;<br><br>function CheckRouterInstance: boolean;<br>begin<br> result := false;<br> if GLOBAL_HELPROUTER <> NIL then raise Exception.Create('Multiple instances of THTMLhelpRouter are not allowed')<br> else result := true;<br>end;<br><br>{ --- THTMLhelpRouter --- }<br><br>constructor THTMLhelpRouter.Create(AOwner: TComponent);<br>begin<br> inherited Create(AOwner);<br> if CheckRouterInstance then<br> begin<br> fAppOnHelp := Application.onhelp;<br> Application.onhelp := OnRouteHelp;<br> GLOBAL_HELPROUTER := Self;<br> end;<br>end;<br><br>destructor THTMLhelpRouter.Destroy;<br>begin<br> if assigned(fAppOnHelp) then Application.onhelp := fAppOnHelp;<br> GLOBAL_HELPROUTER := nil;<br> inherited Destroy;<br>end;<br><br>function THTMLhelpRouter.CurrentForm: TForm;<br>begin<br> if Screen.ActiveForm <> NIL then<br> Result:= Screen.ActiveForm<br> else Result:= Owner as TForm;<br>end;<br><br>procedure THTMLhelpRouter.SetHelpType(value: THelpType);<br>begin<br> if value <> fHelpType then<br> begin<br> fHelpType := value;<br> if fHelpType in [htAuto,htHTMLhelp] then LoadHHCTRL;<br> end;<br>end;<br><br>function THTMLhelpRouter.HTMLhelpInstalled: boolean;<br>begin<br> if HHCTRL = 0 then LoadHHCTRL;<br> result := assigned(HtmlHelpA);<br>end;<br><br>function THTMLhelpRouter.FindHandle(var Helphandle: HWND; var Helpfile: string): boolean;<br>var<br> CForm: TForm;<br>begin<br> case HelpType of<br> htWinhelp: result := false;<br> htHTMLhelp: result := true;<br> htAuto: result := HTMLhelpInstalled;<br> end;<br> HelpFile := Application.helpfile;<br> HelpHandle := Application.handle;<br>{IFDEF VER100}<br> CForm := CurrentForm;<br> if Assigned(CForm) and CForm.HandleAllocated and (CForm.HelpFile <> '') then<br> begin<br> HelpHandle := CForm.Handle;<br> HelpFile := CForm.HelpFile;<br> end;<br>{ENDIF}<br>end;<br><br>function THTMLhelpRouter.OnRouteHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;<br>var<br> showHTML: boolean;<br> rHandle: integer;<br> HelpHandle: HWND;<br> HelpFile: string;<br>// IDS: array[0..2] of DWORD;<br>begin<br> if assigned(fAppOnHelp) then result := fAppOnHelp(command, data, callhelp);<br> if not callHelp then exit;<br><br> showHTML := FindHandle(HelpHandle, HelpFile);<br> result := false;<br> if showHTML then<br> begin<br> rHandle := 0;<br> HelpFile := changefileext(Helpfile,'.chm');<br> case Command of<br> HELP_FINDER, HELP_CONTENTS: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOC, 0); //show table of contents<br> HELP_KEY: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_INDEX, data); //display keywordshow table of contens<br> HELP_QUIT: rHandle := HtmlHelpA(helphandle, nil, HH_CLOSE_ALL, 0);<br> HELP_CONTEXT: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_HELP_CONTEXT, data); //display help context<br> HELP_CONTEXTPOPUP: rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_HELP_CONTEXT, data);<br> end;<br> Result := rHandle <> 0;<br> end;<br><br> if (not result) and (fHelpType <> htHTMLhelp) then<br> begin<br> Result := WinHelp(HelpHandle, PChar(changefileext(HelpFile,'.hlp')), Command, Data);<br> end;<br> CallHelp := false;<br>end;<br><br>function THTMLhelpRouter.HelpContent: boolean;<br>begin<br> result := application.helpcommand(HELP_FINDER, 0);<br>end;<br><br>function THTMLhelpRouter.HelpJump(helpfile, topicid: string): boolean;<br>var<br> Command: array[0..255] of Char;<br> showHTML: boolean;<br> rHandle: integer;<br> HelpHandle: HWND;<br> HFile, HID: string;<br> CForm: TForm;<br>begin<br> result := false;<br> showHTML := FindHandle(HelpHandle, HFile);<br><br> if Helpfile <> '' then<br> begin<br> HFile := HelpFile;<br> HelpHandle := 0;<br> end;<br> if showHTML then<br> begin<br> rHandle := 0;<br> HelpFile := changefileext(HFile,'.chm');<br> HID := TopicID;<br> if copy(lowercase(extractfileext(HID)),1,4) <> '.htm' then HID := HID + '.htm';<br> rHandle := HtmlHelpA(helphandle, pchar(Helpfile+'::/'+HID), HH_DISPLAY_TOPIC, 0); //show table of contents<br> Result := rHandle <> 0;<br> end;<br> if (not result) and (fHelpType <> htHTMLhelp) then<br> begin<br> helpfile := changefileext(HFile,'.hlp');<br> StrLFmt(Command, SizeOf(Command) - 1, 'JumpID("","%s")', [TopicID]);<br> Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br> if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br> end;<br>end;<br><br>function THTMLhelpRouter.HelpPopup(X,Y: integer; text: string): boolean;<br>var<br> CForm: TForm;<br> HP: THH_Popup;<br>begin<br> if (fHelpType <> htWinhelp) and HTMLhelpInstalled then<br> begin<br> CForm := CurrentForm;<br> with HP do<br> begin<br> cbStruct := sizeof(HP);<br> hInstance := 0;<br> idString := 0;<br> pszText := PChar(text);<br> pt.x := X;<br> pt.y := Y;<br> ClientToScreen(CForm.handle, pt);<br> clrForeground := -1;<br> clrBackground := -1;<br> rcMargins.Left := -1;<br> rcMargins.Right := -1;<br> rcMargins.Top := -1;<br> rcMargins.Bottom := -1;<br> pszFont := PChar('MS Sans Serif, 10');<br> end;<br> result := HtmlHelpA(CForm.handle, nil, HH_DISPLAY_TEXT_POPUP, longint(@HP)) <> 0;<br> end<br> else result := false;<br>end;<br><br>function THTMLhelpRouter.HelpKeyword(keyword: string): boolean;<br>var<br> Command: array[0..255] of Char;<br>begin<br> StrLcopy(Command, pchar(keyword), SizeOf(Command) - 1);<br> result := application.helpcommand(HELP_KEY, Longint(@Command));<br>end;<br><br>function THTMLhelpRouter.HelpKLink(keyword: string): boolean;<br>var<br> Command: array[0..255] of Char;<br> showHTML: boolean;<br> rHandle: integer;<br> HelpHandle: HWND;<br> HFile, Helpfile: string;<br> CForm: TForm;<br> HA: THH_AKLINK;<br>begin<br> result := false;<br> showHTML := FindHandle(HelpHandle, HFile);<br><br> if showHTML then<br> begin<br> rHandle := 0;<br> HelpFile := changefileext(HFile,'.chm');<br><br> with HA do<br> begin<br> cbStruct := sizeof(HA);<br> fReserved := false;<br> pszKeywords := pchar(keyword);<br> pszUrl := '';<br> pszMsgText := '';<br> pszMsgTitle := '';<br> pszMsgWindow := '';<br> fIndexOnFail := true;<br> end;<br> rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOPIC, 0); //create window<br> if rHandle <> 0 then rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_KEYWORD_LOOKUP, longint(@HA));<br> Result := rHandle <> 0;<br> end;<br> if (not result) and (fHelpType <> htHTMLhelp) then<br> begin<br> helpfile := changefileext(HFile,'.hlp');<br> StrLFmt(Command, SizeOf(Command) - 1, 'KL("%s",1)', [keyword]);<br> Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br> if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br> end;<br>end;<br><br>function THTMLhelpRouter.HelpALink(akeyword: string): boolean;<br>var<br> Command: array[0..255] of Char;<br> showHTML: boolean;<br> rHandle: integer;<br> HelpHandle: HWND;<br> HFile, Helpfile: string;<br> CForm: TForm;<br> HA: THH_AKLINK;<br>begin<br> result := false;<br> showHTML := FindHandle(HelpHandle, HFile);<br><br> if showHTML then<br> begin<br> rHandle := 0;<br> HelpFile := changefileext(HFile,'.chm');<br><br> with HA do<br> begin<br> cbStruct := sizeof(HA);<br> fReserved := false;<br> pszKeywords := pchar(akeyword);<br> pszUrl := '';<br> pszMsgText := '';<br> pszMsgTitle := '';<br> pszMsgWindow := '';<br> fIndexOnFail := true;<br> end;<br> rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_DISPLAY_TOPIC, 0); //create window<br> if rHandle <> 0 then rHandle := HtmlHelpA(helphandle, pchar(Helpfile), HH_ALINK_LOOKUP, longint(@HA));<br> Result := rHandle <> 0;<br> end;<br> if (not result) and (fHelpType <> htHTMLhelp) then<br> begin<br> helpfile := changefileext(HFile,'.hlp');<br> StrLFmt(Command, SizeOf(Command) - 1, 'AL("%s",1)', [akeyword]);<br> Result := WinHelp(HelpHandle, PChar(Helpfile), HELP_CONTENTS, 0);<br> if Result then Result := WinHelp(HelpHandle, PChar(helpfile), HELP_COMMAND, Longint(@Command));<br> end;<br>end;<br><br><br>procedure Register;<br>begin<br> RegisterComponents('EC', [THTMLhelpRouter]);<br>end;<br><br>initialization<br> HHCTRL := 0;<br><br>finalization<br> if (HHCTRL <> 0) then FreeLibrary(HHCTRL);<br>end.<br>//*****************