unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,mmsystem,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
hotkeyid :integer;
procedure WMhotkeyhandle(var msg:Tmessage);
message wm_hotkey; //响应敏感键按键消息
public
{ Public declarations }
end;
var
Form1: TForm1;
showit:boolean=false;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
hotkeyid:=GlobalAddAtom(pchar('UserDefineHotKey'))-$C000;
//减去$C000是为了保证取值范围的限制
registerhotkey(handle,hotkeyid,MOD_CONTROL+MOD_ALt,$41);
//敏感键为ctrl+Alt+A
end;
procedure TForm1.Wmhotkeyhandle(var msg:Tmessage);
begin
if (msg.LParamHi=$41)then
begin
msg.Result:=1; //该消息已经处理
if showit then begin
Form1.Show;
showit:=false;
end
else
begin
form1.Hide;
showit:=true;
end;
//把窗口最前面显示
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
unregisterhotkey(handle,hotkeyid);
DeleteAtom(HotKeyID);
end;
end.