unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi;
const
WM_NOTIFYTRAYICON = WM_USER + 1;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure WMTRAYICONNOTIFY(var Msg: TMessage);
message WM_NOTIFYTRAYICON;
public
end;
var
Form1: TForm1;
tray: TNotifyIconData;
TrayIcon: TIcon;
implementation
{$R *.dfm}
procedure TForm1.WMTRAYICONNOTIFY(var Msg: TMessage);
begin
case Msg.LParam of
WM_LBUTTONDOWN: Form1.Visible:=true;
WM_LBUTTONDBLCLK:
WM_LBUTTONUP:
WM_RBUTTONDOWN:
WM_RBUTTONDBLCLK:
WM_RBUTTONUP:
WM_MOUSEMOVE:
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
try
with tray do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Form1.Handle;
uID := 1;
end;
Shell_NotifyIcon(NIM_DELETE, Addr(tray));
finally
Application.Terminate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TrayIcon := Application.Icon;
with tray do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Form1.Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage := WM_NOTIFYTRAYICON;
hIcon := TrayIcon.Handle;
szTip := ("Это мое приложение в трее");
end;
Shell_NotifyIcon(NIM_ADD, Addr(tray));
end;
procedure TForm1.GoToTrayButtonClick(Sender: TObject);
begin
Form1.Visible:=false;
end;
end.