5,388
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
_HotKey:Integer;
procedure HotKey(var Msg:Tmessage);message WM_HOTKEY;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ShellApi;
{$R *.dfm}
procedure doNotifyIconData(aType: String);
var
lpData: PNotifyIconData;
begin
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;
lpData.Wnd := Form1.Handle;
lpData.hIcon := Application.Icon.Handle;
lpData.uID :=0;
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
if (aType = 'add') then
Shell_NotifyIcon(NIM_ADD, lpData)
else if (aType = 'del') then
Shell_NotifyIcon(NIM_DELETE, lpData);
dispose(lpData);
end;
procedure TForm1.HotKey(var Msg:Tmessage);
begin
if Msg.LParamHi=vk_F2 then
begin
if self.Visible then
begin
doNotifyIconData('del');
self.Visible:=false;
end else
begin
doNotifyIconData('add');
self.Visible:=true;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
_HotKey:=GlobalAddAtom('HotKey')-$C000;
RegisterHotKey(Handle,_HotKey,0,vk_F2); {取出用户设定的热键,把vk_F2变一下即可}
doNotifyIconData('add');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle,_HotKey);
end;
end.