在DelPhi中调用CHM文件的大致做法如下:
1.在程序开始的uses部分加入‘ShellAPI',位置随意。这个操作的目的是通知计算机本程序将使用SHellAPI中的函数。程序段如下。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, ...,ShellAPI,...;
2.对于具体进行CHM文件操作的语句,可以设置一个过程。可参考的过程如下。(假设CHM文件的文件名是AAA.CHM)
procedure TForm1.OpenCHM;
var
p:pchar;
begin
if FileExists(ExtractFilePath(Application.Exename)+'AAA.chm') then
begin
p:=pchar(ExtractFilePath(Application.Exename)+'AAA.chm');
ShellExecute(0, nil, p, nil, nil, SW_NORMAL);
end
else
begin
MessageBox(Form1.Handle,' 没有帮助文件 ! ','提示信息', MB_OK or MB_ICONINFORMATION);
end;
end;
在需要调用CHM文件时,调用这个过程即可。
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_F1 then
ShellExecute(Form1.Handle, "open", 'myhelp.chm', '', '', SW_SHOWNORMAL);
end;