给你一段代码参考吧。
需要包含:use shellapiWM_USER_NOTIFYICON=WM_USER+500;
///自定义消息。procedure OnMyNotifyIcon(var Msg:TMessage);message WM_USER_NOTIFYICON;
//图标点击回调函数。procedure TForm1.Button1Click(Sender: TObject);
var
tnd:pNOTIFYICONDATA;
begin
new(tnd);
tnd.cbSize:=sizeof(NOTIFYICONDATA);
tnd.Wnd := Handle;
tnd.uID := 0;
tnd.uFlags:=(NIF_MESSAGE) or (NIF_ICON or NIF_TIP);
tnd.uCallbackMessage := WM_USER_NOTIFYICON;
tnd.hIcon := LoadIcon(HInstance,'MAINICON');
Shell_NotifyIcon(NIM_ADD,tnd);
FreeMem(tnd);
end;
//---------------------------------------------------------------------------
procedure TForm1.OnMyNotifyIcon(var Msg:TMessage);
var
Pos:TPoint;
begin
case Msg.LParam of
WM_RBUTTONDOWN:
begin
SetForegroundWindow(Handle);
GetCursorPos(Pos);
PopupMenu1.Popup(pos.x,Pos.y);
end;
end;
end;
需要包含:use shellapiWM_USER_NOTIFYICON=WM_USER+500;
///自定义消息。procedure OnMyNotifyIcon(var Msg:TMessage);message WM_USER_NOTIFYICON;
//图标点击回调函数。procedure TForm1.Button1Click(Sender: TObject);
var
tnd:pNOTIFYICONDATA;
begin
new(tnd);
tnd.cbSize:=sizeof(NOTIFYICONDATA);
tnd.Wnd := Handle;
tnd.uID := 0;
tnd.uFlags:=(NIF_MESSAGE) or (NIF_ICON or NIF_TIP);
tnd.uCallbackMessage := WM_USER_NOTIFYICON;
tnd.hIcon := LoadIcon(HInstance,'MAINICON');
Shell_NotifyIcon(NIM_ADD,tnd);
FreeMem(tnd);
end;
//---------------------------------------------------------------------------
procedure TForm1.OnMyNotifyIcon(var Msg:TMessage);
var
Pos:TPoint;
begin
case Msg.LParam of
WM_RBUTTONDOWN:
begin
SetForegroundWindow(Handle);
GetCursorPos(Pos);
PopupMenu1.Popup(pos.x,Pos.y);
end;
end;
end;
1:从网上下载这个控件
2:
var
TNID:PNotifyIconData;
HCurrentIcon1:TIcon;Procedure NotifyIcon(dwMessage:DWORD;HHIcon:TIcon;Tip:PChar);
begin
if(dwMessage=NIM_ADD) or(dwMessage=NIM_DELETE) or (dwMessage=NIM_MODIFY) then
begin
With TNID^ do
begin
Wnd:=Form1.Handle;
uiD:=100;
uCallBackMessage:=Tray_Message;
uFlags:=NIF_MESSAGE;
end;
if(HHIcon<>nil) then
begin
TNID^.UFlags:=TNID^.uFlags or NIF_ICON;
TNID^.hIcon:=HHICON.Handle;
end;
if(Tip<>NIl) then
begin
TNID^.uFlags:=TNID^.uFlags or NIF_Tip;
StrPcopy(TNID^.szTip,Tip);
end;
Shell_NotiFyIcon(dwMessage,TNID);
end;
end;begin
TNID:=new(PNOTIfYICONDATA);
HCurrentIcon1:=TIcon.Create;
HCurrentIcon1.LoadFromFile('blue.ico');
NotifyIcon(NiM_ADD,HCurrentIcon1,PChar('AntoAnte'));
end;
留下email。