各位大虾请救急:如何在DELPHI6里有效的使用CHM帮助文件,最好能……
各位大虾请救急:如何在DELPHI6里有效的使用CHM帮助文件,最好能像DELPHI6
里面的那样,能根据用户所处的情况自动跳至相应的帮助内容。先谢谢各位大哥了。:)
问题点数:99、回复次数:2Top
1 楼linwf(木木)回复于 2002-10-11 13:24:42 得分 29
你可以这样
application.HelpFile := 'flow.hlp';
application.HelpCommand(HELP_CONTEXT, intIndex);
你要在flow.hlp遍写好,intIndex对应某一个页面Top
2 楼cmmi(大彬)回复于 2002-10-11 14:58:47 得分 70
希望下面的文章对你有所帮助!
文章来源:http://www.ccw.com.cn/htm/app/aprog/01_5_18_4.asp
Delphi并不支持HTML HELP帮助系统,它仍然使用WinHelp。笔者通过反复尝试,发现调用Windows系统目录System32下的HHCTRL.OCX,利用其中的HtmlHelpA函数接口可以自行实现HTML HELP帮助。
公共模块代码如下:
unit HTMLHELPCOMMON
interface
uses Windows;
type
DWORD_PTR = ^DWORD;
Function
HtmlHelp(hwndCaller:HWND;strFile:String;
uCommand:UINT; dwData:DWORD_PTR ):HWND;
procedure CloseHtmlHelp;
implementation
uses
SysUtils;
const
HHControlInstance:THandle=0;
dwCookie :DWORD = 0;
var
HtmlHelpA:function ( hwndCaller:HWND; pszFile:PChar ;
uCommand:UINT; dwData:DWORD_PTR ):HWND;stdcall;
function HtmlHelp(hwndCaller:HWND;strFile:String;
uCommand:UINT; dwData:DWORD_PTR ):HWND;
var
LFileName:String;
p:PChar;
begin
if HHControlInstance=0 then
begin
LFileName := StringOfChar( ' ', 256);
p := PChar( LFilename );
GetSystemDirectory(p,255);
StrCat(p,'\HHCTRL.OCX');
HHControlInstance := LoadLibrary( P );
if HHControlInstance = 0 then
raise exception.Create('Help system not installed!'#13' HTMLHELP cannot displayed!');
@HtmlHelpA := GetProcAddress( HHControlInstance, 'HtmlHelpA');
if @HtmlHelpA = nil then
raise exception.Create('Function HTMLHELP cannot loaded!');
HtmlHelpA( 0, nil,$001C , (@dwCookie));
end;
result := HtmlHelpA( hwndCaller, PChar( strFile ), uCommand, dwData );
end;
procedure CloseHtmlHelp;
begin
if HHControlInstance<>0 then
begin
HtmlHelpA( 0, nil, $001D, DWORD_PTR(dwCookie));
FreeLibrary(HHControlInstance);
end;
end;
end.
两个函数分别初始化和释放调用接口。其它模块只须按约定调用即可。例如:
HtmlHelp( handle, htmlhelpfilename+'::/welcome.htm',$0000, nil);
显示htmlhelpfilename对应的帮助文件的welcome页面。
上下文敏感帮助需要借用Delphi对WinHelp的支持。当用户按 F1 键时,程序将自动触发OnHelp事件,截获它,编写自己的处理代码即可。
... ...
Application.HelpFile := htmlhelpfilename;
tmpOnHelp := Application.OnHelp;
Application.OnHelp := AppHtmlHelp;
... ...
function TForm1.AppHtmlHelp(Command: Word; Data: Longint;
var CallHelp: Boolean): Boolean;
var ret:integer;Hfile:string;
begin
if not CallHelp then exit;
AppPath := ExtractFilePath(Application.ExeName);
Hfile := AppPath + Application.HelpFile;
case Command of
HELP_FINDER, HELP_CONTENTS:
ret := HtmlHelp(handle, pchar(Hfile), $0001, nil);
HELP_QUIT:
ret := HtmlHelp(0, '', $0012, nil);
HELP_CONTEXT:
ret := HtmlHelp(handle, pchar(Hfile), $000f, DWORD_PTR(data));
end;
result:=ret<>0;
CallHelp := False;
end;
这样,我们就有另一种方法调用帮助文件,与传统WinHelp调用方法一样:
application.helpcommand(HELP_FINDER, 0);
application.helpcommand(HELP_quit, 0);
... ...
Top




