function Shell_NotifyIcon(dwMessage:DWORD;lpData:PNotifyIconData):BOOL;stdcall;
在shellapi单元中。
dwMessage:NIM_ADD
NIM_MODIFY
NIM_DELETE
PNotifyIconData=^TNotifyIconDataA
TNotifyIconDataA=record
cbSize:DWORD;
Wnd:HWND;
uID:UINT;
uFlags:UINT;
uCallbackMessage:UINT;
hIcon:HICON;
szTip:array[0..63] of AnsiChar;
end;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
const
MyIconID=1;
MyIconEvent=WM_USER+1;
...
private
...
MyIcon:TIcon;
...
//Install
var
IconData:TNotifyIcon;
...
MyIcon:=TIcon.Create;
MyIcon.LoadFromFile('icon1.ico');
with IconData do
begin
cbSize:=SizeOf(IconData); //
Wnd:=Form1.Handle; //
uID:=MyIconID; //
uFlags:=NIF_ICON;
uCallBackMessage:=MyIconEvent;
hIcon:=Handle; //Change
szTip:='My Test Icon';
Shell_NotifyIcon(NIM_ADD,@IconData);
...
//做了标记的是改或删时要设的。
//precedure IconOnClick(msg:TMessage);message MyIconEvent;
if(msg.lParam=WM_RBUTTONDOWN) then
GetCursorPos(p); //p:TPoint;
PopupMenu1.Popup(p.x,p.y);