unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
hotkeyid : array[1..5] of integer;
procedure WMhotkeyhandle(var msg:Tmessage);
message wm_hotkey;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.WMhotkeyhandle(var msg: Tmessage);
begin
if (msg.LParamHi = $41) and (msg.LParamLo = mod_control or mod_alt) then
begin
application.BringToFront;
end;
if msg.LParamHi = vk_F5 then
application.Restore;
if msg.LParamHi = vk_F6 then
application.Minimize;
if msg.LParamHi = vk_F7 then
showmessage(datetostr(now()));
if msg.LParamHi = vk_F8 then
application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
for i :=1 to 5 do
hotkeyid := globaladdatom(pchar('myhotkey'+inttostr(i)))-$c0000;
registerhotkey(handle,hotkeyid[1],mod_control or mod_alt,$41);
registerhotkey(handle,hotkeyid[2],0,vk_F5);
registerhotkey(handle,hotkeyid[3],0,vk_F6);
registerhotkey(handle,hotkeyid[4],0,vk_F7);
registerhotkey(handle,hotkeyid[5],0,vk_F8);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i : integer;
begin
for i := 1 to 5 do
unregisterhotkey(handle,hotkeyid);
deleteatom(hotkeyid);
end;
end. |