delphi 打开CHM文件(100分)

  • 主题发起人 主题发起人 xiaoguai051
  • 开始时间 开始时间
X

xiaoguai051

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样让按一下按钮就打开一个CHM文件如
HELP。CHM
ShellExecute(handle,nil,'D:/HELP.chm',nil,nil,Sw_shownormal);
这样打不开啊,怎么改呢
 
不做修改,可以正常打开。
不然改成这样试试:
ShellExecute(handle,'open','hh.exe','D:/HELP.chm',nil,Sw_shownormal);
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,shellapi;

type
TForm1 = class(TForm)
lbl1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
HotKeyId: Integer;
implementation

{$R *.DFM}


procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LParamHi = VK_F1) then // ALT+F1 (Msg.LparamLo = MOD_ALT) AND (Msg.LParamHi = VK_F1)
begin
//ShowMessage('F1');
if FileExists('help.chm') then
ShellExecute(handle,nil,'help.chm',nil,nil,Sw_shownormal)
else
ShowMessage('help.chm不存在');
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin

HotKeyId := GlobalAddAtom('MyHotKey') - $C000;
RegisterHotKey(Handle, hotkeyid, 0, VK_F1); //F1
// RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F1); //ALT+F1
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle, HotKeyId); //注销HotKey

end;

end.
 
多人接受答案了。
 
后退
顶部