添加任务栏系统图标
自定义消息
const
icoMsg = wm_user + 1;
iid = 100;
获取鼠标点击消息
procedure iconMessage(var message: TMessage); message icoMsg;
procedure TForm1.iconMessage(var message: TMessage);
var
mypt: Tpoint;
begin
inherited;
if message.LParam = WM_RBUTTONUP then //右键点击的位置显示弹出菜单
begin
getCursorPos(mypt);
PopupMenu.Popup(mypt.X, mypt.Y);
end;
if message.LParam = WM_LBUTTONUP then //左键点击显示主界面
begin
if Showing then
Hide
else
begin
Show;
end;
end;
message.Result := 0;
end;
创建和释放
procedure TForm1.FormCreate(Sender: TObject);
begin
ntid.cbsize := sizeof(TnotifyIconDataA);
ntid.Wnd := Handle;
ntid.uID := iid;
ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
ntid.uCallbackMessage := icoMsg;
ntid.hIcon := Application.Icon.Handle;
Move(self.caption[1],ntid.sztip,Length(Caption));
shell_notifyicona(NIM_ADD, @ntid);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @ntid);
end;