先把form1的keypreview设置为true,然后: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key= vk_f1 then showmessage(''); end;
上下文敏感帮助需要借用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); ... ...
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=$70 then form2.show; end;
keypreview设置为true procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=112 then ShellExecute(Handle, 'open', Pchar('c:\help.chm'), nil, nil, SW_SHOWNORMAL);end;
If Msg.message = Wm_KeyDown Then Begin Case Msg.wParam Of VK_F1: Begin PubFun_unit.CallHelp(0); End; End; End;
我认为这样比较稳定 1.加一个Actionlist(standard页) 2.双击Actionlist 3.单击 new action 4.双击 刚加的action procedure TTransComWaveoutForm.HelpExecute(Sender: TObject); begin winexec(filename,sw_shownormal); end; 5.将shortcut 设置成F1
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key= vk_f1 then
showmessage('');
end;
公共模块代码如下: 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);
... ...
Shift: TShiftState);
begin
if key=$70 then
form2.show;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=112 then
ShellExecute(Handle, 'open', Pchar('c:\help.chm'), nil, nil, SW_SHOWNORMAL);end;
Begin
Case Msg.wParam Of
VK_F1:
Begin
PubFun_unit.CallHelp(0);
End;
End;
End;
1.加一个Actionlist(standard页)
2.双击Actionlist
3.单击 new action
4.双击 刚加的action
procedure TTransComWaveoutForm.HelpExecute(Sender: TObject);
begin
winexec(filename,sw_shownormal);
end;
5.将shortcut 设置成F1