第一帖测试下CSDN的效果、copy一份网络上的东西看看效果、、
type TForm1 = class(TForm) Label1: TLabel; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } aatom:atom; procedure hotkey(var msg:tmessage);message wm_hotkey; //定义全局热键消息事件 public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin aatom:=globaladdatom('hotkey'); //全局热键ID RegisterHotKey(handle,aatom,MOD_ALT,vk_f12); //注册全局热键 end; procedure TForm1.hotkey(var msg:tmessage); //热键响应事件 begin if (msg.LParamHi=VK_F12) and (msg.LParamLo=MOD_ALT) then //全局热键 ALT+F12 ShowWindow(Application.Handle, SW_RESTORE); //当目标窗口没有最小化而是层叠在后台时无效,只能用于显示隐藏或最小化的窗体 SetForegroundWindow(form1.handle); //当目标窗体最小化后此句无效,只能改变窗体z序列前后位置 end; //note:以上两个API合用时才能达到随时激活隐藏窗体的效果 procedure TForm1.FormDestroy(Sender: TObject); //销毁全局热键 begin globalDeleteatom(aatom); end;