参照 程序元2000的代码UNIT1
USES shellaoi,.....;
....
const WM_NOTIFYICON= WM_USER + 1;
private
NotifyData:TnotifyIconData;
procedure ADDIcon;
procedure RemoveIcon;
protected
procedure OnNotifyIcon(VAR message :Tmessage);
message WN_NOTIFYICON;
procedure TFORM1.ADDICON;
begin
Notifydata.cbSize:=sizeof(notifydata);
with Notifydata do
begin
Wnd:=Handle;
uID:=1;
uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
hICON:=APPLICATION.ICON.Handle;
szTip:='你的程序';
uCallbackMessage:=WM_NOTIFYICON;
end;
Shell_NotifyIcon(NIM_ADD,@Notifydata);
end;procedure Tform1.RemoveIcon;
begin
NotifyIcon.Uid:=1;
Shell_NotifyIcon(NIM_DELETE,@NOTIFYDATA);
end;procedure TForm1.Button1click(sender:tobject);
begin
addicon;
end;procedure Tform2.buttonclick(sender:tobject);
begin
removeicon;
end;在form1上放一个popmenu,
procedure Tform1.onNotifyIcon(var Message:Tmessage);
var mousepos:tpoint;
begin
if Message.lparam= WM_LBUTTONDBLCLK then
showmessage('运行了?')
else
if (Message.lparam= WM_LBUTTONDOWN) then
Begin
GetCursorpos(MousePos);
Setforegroudwindow(application.handle);
Application.ProcessMessages;
popmenu.popup(mousepos.x,mousepos.y);
end;
end;
USES shellaoi,.....;
....
const WM_NOTIFYICON= WM_USER + 1;
private
NotifyData:TnotifyIconData;
procedure ADDIcon;
procedure RemoveIcon;
protected
procedure OnNotifyIcon(VAR message :Tmessage);
message WN_NOTIFYICON;
procedure TFORM1.ADDICON;
begin
Notifydata.cbSize:=sizeof(notifydata);
with Notifydata do
begin
Wnd:=Handle;
uID:=1;
uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
hICON:=APPLICATION.ICON.Handle;
szTip:='你的程序';
uCallbackMessage:=WM_NOTIFYICON;
end;
Shell_NotifyIcon(NIM_ADD,@Notifydata);
end;procedure Tform1.RemoveIcon;
begin
NotifyIcon.Uid:=1;
Shell_NotifyIcon(NIM_DELETE,@NOTIFYDATA);
end;procedure TForm1.Button1click(sender:tobject);
begin
addicon;
end;procedure Tform2.buttonclick(sender:tobject);
begin
removeicon;
end;在form1上放一个popmenu,
procedure Tform1.onNotifyIcon(var Message:Tmessage);
var mousepos:tpoint;
begin
if Message.lparam= WM_LBUTTONDBLCLK then
showmessage('运行了?')
else
if (Message.lparam= WM_LBUTTONDOWN) then
Begin
GetCursorpos(MousePos);
Setforegroudwindow(application.handle);
Application.ProcessMessages;
popmenu.popup(mousepos.x,mousepos.y);
end;
end;
:回复人: ydx(21世纪不编程,编程就用BCB) (2001-9-14 14:27:47) 得0分
可是我一击任务栏的图标就出现错误。
回复人: duduwolf(嘟嘟狼) (2001-9-14 14:49:41) 得0分
放一个TrayIcon,设Visible=true;
在工程文件内加一行Application->ShowMainForm = false;
就OK了。