unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
keyid:integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
//注册系统级热键
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
keyid:=globaladdatom(pchar('wcgkey'));
registerhotkey(self.Handle,keyid,0,vk_f2);
end;
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
//响应
if msg.HotKey=keyid then
begin
application.Restore;
application.BringToFront;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//销毁系统级热键
windows.UnregisterHotKey(self.Handle,keyid);
windows.GlobalDeleteAtom(keyid);
end;
end.