給你源碼: unit HHComp; {This is freeware Delphi unit which allow to use HTMLHelp instead of usual Windows Help intercepting OnHelp event. Using this component you can still use HelpContext properties of the components but THHComp redirect help request to the HTMLHelp API. Only one component per programm can be used. Copyright (c) 2001 Ainars Skangals This component is provided "as is" without warranty of any kind, either expressed or implied. } interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;const HH_DISPLAY_TOPIC = $0000; HH_DISPLAY_TOC = $0001; HH_DISPLAY_INDEX = $0002; HH_HELP_CONTEXT = $000F; HH_CLOSE_ALL = $0012;type THHComp = class(TComponent) private { Private declarations } FHelp:String; protected { Protected declarations } procedure Loaded; override; public { Public declarations } Function ShowContents:Integer; Function ShowIndex:Integer; Function ShowHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean; Destructor Destroy; override; published { Published declarations } Property HelpFile:String read FHelp write FHelp; end;procedure Register;implementationfunction HHelp(hwndCaller : HWND; pszFile: PChar; uCommand : Integer; dwData : DWORD) : HWND; stdcall; external 'hhctrl.ocx' name 'HtmlHelpA';function THHComp.ShowContents:Integer; begin Result:=HHelp(Application.Handle,PChar(FHelp),HH_DISPLAY_TOC,0); end;function THHComp.ShowIndex:Integer; begin Result:=HHelp(Application.Handle,PChar(FHelp),HH_DISPLAY_INDEX,0); end;function THHComp.ShowHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean; begin if FHelp<>'' then HHelp(Application.Handle,PChar(FHelp),HH_HELP_CONTEXT,Data); CallHelp:=False; Result:=true; end;procedure THHComp.Loaded; begin Inherited; // Here the help system is switched to HTMLHelp Application.OnHelp:=ShowHelp; end;destructor THHComp.Destroy; begin // Automatically close help window if any HHelp(0,PChar(FHelp),HH_CLOSE_ALL,0); inherited; end;procedure Register; begin RegisterComponents('HAHA', [THHComp]); end;end.
設置HHComp1.HelpFile := 'help.chm';
HHComp1.ShowContents;//內容
HHComp1.ShowIndex;//索引
unit HHComp;
{This is freeware Delphi unit which allow to use HTMLHelp instead of usual Windows Help
intercepting OnHelp event. Using this component you can still use HelpContext properties
of the components but THHComp redirect help request to the HTMLHelp API.
Only one component per programm can be used.
Copyright (c) 2001 Ainars Skangals
This component is provided "as is" without warranty of any kind,
either expressed or implied.
}
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;const
HH_DISPLAY_TOPIC = $0000;
HH_DISPLAY_TOC = $0001;
HH_DISPLAY_INDEX = $0002;
HH_HELP_CONTEXT = $000F;
HH_CLOSE_ALL = $0012;type
THHComp = class(TComponent)
private
{ Private declarations }
FHelp:String;
protected
{ Protected declarations }
procedure Loaded; override;
public
{ Public declarations }
Function ShowContents:Integer;
Function ShowIndex:Integer;
Function ShowHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
Destructor Destroy; override;
published
{ Published declarations }
Property HelpFile:String read FHelp write FHelp;
end;procedure Register;implementationfunction HHelp(hwndCaller : HWND; pszFile: PChar; uCommand : Integer;
dwData : DWORD) : HWND; stdcall; external 'hhctrl.ocx' name 'HtmlHelpA';function THHComp.ShowContents:Integer;
begin
Result:=HHelp(Application.Handle,PChar(FHelp),HH_DISPLAY_TOC,0);
end;function THHComp.ShowIndex:Integer;
begin
Result:=HHelp(Application.Handle,PChar(FHelp),HH_DISPLAY_INDEX,0);
end;function THHComp.ShowHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
begin
if FHelp<>'' then
HHelp(Application.Handle,PChar(FHelp),HH_HELP_CONTEXT,Data);
CallHelp:=False;
Result:=true;
end;procedure THHComp.Loaded;
begin
Inherited;
// Here the help system is switched to HTMLHelp
Application.OnHelp:=ShowHelp;
end;destructor THHComp.Destroy;
begin
// Automatically close help window if any
HHelp(0,PChar(FHelp),HH_CLOSE_ALL,0);
inherited;
end;procedure Register;
begin
RegisterComponents('HAHA', [THHComp]);
end;end.