var
Form1: TForm1;
nid:Tnotifyicondataa;
implementation
{$R *.DFM}
procedure Tform1.InstallIcon;
begin
nid.cbsize:=sizeof(nid);
nid.wnd:=handle;
nid.uid:=0;
nid.hIcon:=Application.icon.handle;
nid.sztip:='这里是你的提示信息!';
nid.uCallBackMessage:=my_message;
nid.uflags:=nif_icon or nif_tip or nif_message;
shell_notifyIcon(NIM_ADD,@nid);
end;
procedure Tform1.OnMymssg(var msg : Tmessage);
var
mou:Tmouse;
begin
mou:=Tmouse.Create;
try
if msg.LParam=WM_LBUTTONUP then
begin
form1.Visible:=true;
setforegroundwindow(form1.handle);
OpenIcon(Application.Handle);
shell_notifyicon(NIM_DELETE,@nid);
end
else if msg.LParam=WM_RBUTTONUP then
PopupMenu1.Popup(mou.CursorPos.x,mou.cursorpos.y);
finally
mou.Free;
end;
end;
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
installicon;
form1.Hide;
end;
procedure TForm1.N1Click(Sender: TObject);
begin
Close;
end;
end.
注册系统热键——(要在USES里加上registry)
//注册热键(ctrl、alt和A)
RegisterHotKey(handle,0,MOD_ALT or MOD_CONTROL,Ord('A'));
//当按下定义好的热键时,窗口弹出,并成为当前激活窗口
procedure TForm1.WMHOTKEY(var Message:TMessage);
begin
Form1.Visible:=True;
Setforegroundwindow(form1.handle);
OpenIcon(Application.Handle);
Shell_notifyicon(NIM_DELETE,@nid);
end;
var
Form1: TForm1;
IconData: TNotifyIconData; //图标
implementation
{$R *.DFM}
//处理 CM_TRAYICON 的事件
procedure TForm1.CMTrayIcon(var Message: TMessage);
var
P: TPoint;
begin
try
with Message do
//如果单击鼠标左键或右键,弹出菜单
if (lParam = WM_LBUTTONUP)or(lParam = WM_RBUTTONUP) then
begin
GetCursorPos(P);
PopupMenu1.Popup(P.X, P.Y);
end;
except
end;
end;
//系统最小化时调用的事件
procedure TForm1.MyMinimize(Sender: TObject);
begin
Hide;
end;
procedure TForm1.RestoreItemClick(Sender: TObject);
begin
Application.MainForm.Show;
procedure TForm1.IconOnClick( var message: Tmessage);
var p : TPoint;
begin
if (message.lParam = WM_LBUTTONDOWN) then
ShowWindow( Application.Handle, SW_SHOW );
if (message.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos( p );
pop1.Popup( p.x ,p.y );
ChangeIcon( status );
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnInstallIcon;
normalicon.Free;
disabledicon.Free;
end;
procedure TForm1.close1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.status1Click(Sender: TObject);
begin
status := not status;
if status then
status1.Caption := 'Enable'
else
status1.Caption := 'Disable';
end;
procedure TForm1.n1Click(Sender: TObject);
begin
Application.Restore;
Application.BringToFront;
end;
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure tform1.formcreate(sender.....);
begin
registerhotkey(handle,1002,0,vk_f10);//注册F10为热键
registerhotkey(handle,1003,mod_control,65);//注册ctrl+a
registerhotkey(handle,1004,mod_control+mod_alt,ord('a'));//注册ctrl+alt+a
registerhotkey(handle,1001,mod_win,65);//注册win+a,win 就是ctrl和alt中间的键
end
procedure tform1.wmhotkey(var msg:tmessage);
begin
if msg.wparam=1001 then
//自己写事件
procedure tform1.formdestroy(sender:tobject);
begin
unregisterhotkey(handle,1001);//释放注册的热键
end;