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);