const WM_MYTRAYICONCALLBACK = WM_USER+1966;
type
TMainForm = class(TForm)
PopupMenu1: TPopupMenu;
N1111: TMenuItem;
N2221: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
MyTrayIcon : TNotifyIconData;
procedure WMMyTrayIconCallBack(var Msg : TMessage);
Message WM_MYTRAYICONCALLBACK;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
MyTrayIcon.cbSize := SizeOf(TNotifyIconData);
MyTrayIcon.Wnd := Handle;
MyTrayIcon.uID :=1;
MyTrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
MyTrayIcon.uCallBackMessage := WM_MYTRAYICONCALLBACK;
MyTrayIcon.hIcon := Icon.Handle;//使用了主窗口的图标
MyTrayIcon.szTip := '鼠标放上去的提示';
Shell_NotifyIcon(NIM_ADD,@MyTrayIcon);
end;
procedure TMainForm.WMMyTrayIconCallBack(var Msg: TMessage);
begin
case Msg.LParam of
WM_RBUTTONDOWN:
//在小图标上点右键了,你准备干什么;
WM_LBUTTONDOWN:
//在小图标上点左键了,你准备干什么
WM_MBUTTONDOWN:
//在小图标上点中键了,你准备干什么
end;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@MyTrayIcon);
end;