我找了一些资料:
通用单元
===================================
unit HTMLHELPCOMMON;
interface
uses Windows;
type
DWORD_PTR = ^DWORD;
Function HtmlHelp(hwndCaller:HWND;strFile:String;
uCommand:UINT;
dwData
WORD_PTR ):HWND;
procedure CloseHtmlHelp;
implementation
uses SysUtils;
const
HHControlInstance:THandle=0;
dwCookie
WORD = 0;
var
HtmlHelpA:function ( hwndCaller:HWND;
pszFile
Char ;
uCommand:UINT;
dwData
WORD_PTR ):HWND;stdcall;
function HtmlHelp(hwndCaller:HWND;strFile:String;uCommand:UINT;
dwData
WORD_PTR ):HWND;
var
LFileName:String;
p
Char;
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.
调用单元(窗体)
===================================
unit TestHelp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ToolWin, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
SpeedButton1: TSpeedButton;
MainMenu1: TMainMenu;
ggg1: TMenuItem;
jjk1: TMenuItem;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
procedure FormCreate(Sender: TObject);
function AppHtmlHelp(Command: Word;
Data: Longint;
var CallHelp: Boolean): Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses HTMLHELPCOMMON;
{$R *.DFM}
function TForm1.AppHtmlHelp(Command: Word;
Data: Longint;
var CallHelp: Boolean): Boolean;
var
ret:integer;
Hfile,AppPath:string;
begin
if not CallHelp then
exit;
AppPath := ExtractFilePath(Application.ExeName);
Hfile := 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;
procedure TForm1.FormCreate(Sender: TObject);
var
htmlhelpfilename:string;
begin
htmlhelpfilename:=ExtractFilePath(Application.ExeName)+'ngmfhelp.chm';
Application.HelpFile := htmlhelpfilename;
//tmpOnHelp := Application.OnHelp;
Application.OnHelp := AppHtmlHelp;
end;
end.
但问题是:
在普通的工程中能够正常运行!
但如果是在DLL中使用:
假设上面的调用单元是主程序,
在主程序调用的 DLL中也能调出帮助文件(HelpContext,要把主程序的Applicatin传给 DLL),
可主程序在退出时会出现一堆错误,
如何解决?