unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics,<br> Controls, Forms, Dialogs, ExtCtrls, ShellAPI;<br><br>const<br> WM_TRAYNOTIFY=WM_USER+1;//定义通知消息<br><br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> procedure FormCreate(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure WndProc(var Msg: TMessage); override;<br> end;<br><br>var<br> Form1: TForm1;<br> nd0, nd1:NotifyIconData;<br> hs:array[0..9]of LongWord;<br><br>implementation<br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> //加载Icon0..Icon9这10个图标资源,<br>并且保存它们的句柄。<br> //图标Icon0..Icon9分别对应与0..9这9个数字。<br> hs[0]:=LoadIcon(hInstance, 'Icon0');<br> hs[1]:=LoadIcon(hInstance, 'Icon1');<br> hs[2]:=LoadIcon(hInstance, 'Icon2');<br> hs[3]:=LoadIcon(hInstance, 'Icon3');<br> hs[4]:=LoadIcon(hInstance, 'Icon4');<br> hs[5]:=LoadIcon(hInstance, 'Icon5');<br> hs[6]:=LoadIcon(hInstance, 'Icon6');<br> hs[7]:=LoadIcon(hInstance, 'Icon7');<br> hs[8]:=LoadIcon(hInstance, 'Icon8');<br> hs[9]:=LoadIcon(hInstance, 'Icon9');<br><br> //填充NotifyIconData记录型变量nd0<br> nd0.cbSize := sizeof(NotifyIconData);<br> nd0.Wnd := handle;<br> nd0.uID := 0;<br> nd0.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br> nd0.uCallbackMessage := WM_TRAYNOTIFY;<br> nd0.hIcon := hs[0];<br> StrPLCopy(nd0.szTip, 'Hello, World!', 63);<br><br> //填充NotifyIconData记录型变量nd1<br> nd1.cbSize := sizeof(NotifyIconData);<br> nd1.Wnd := handle;<br> nd1.uID := 1;<br> nd1.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br> nd1.uCallbackMessage := WM_TRAYNOTIFY;<br> nd1.hIcon := hs[0];<br> StrPLCopy(nd1.szTip, 'Simon Loves Daisy', 63);<br><br> //在任务栏状态区添加图标<br> Shell_NotifyIcon(NIM_ADD, @nd0);<br> Shell_NotifyIcon(NIM_ADD, @nd1);<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> st:SystemTime;<br>begin<br> //每秒钟更新一次图标:图标0显示秒数的十位,<br>图标1显示秒数的个位。<br> GetLocalTime(st);<br> nd0.hIcon := hs[st.wSecond div 10];<br> nd1.hIcon := hs[st.wSecond mod 10];<br> //修改任务栏状态区的图标<br> Shell_NotifyIcon(NIM_MODIFY, @nd0);<br> Shell_NotifyIcon(NIM_MODIFY, @nd1);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> //将图标从任务栏状态区删除<br> Shell_NotifyIcon(NIM_DELETE, @nd0);<br> Shell_NotifyIcon(NIM_DELETE, @nd1);<br>end;<br><br>//处理 通知消息<br>procedure TForm1.WndProc(var Msg: TMessage);<br>var<br> IconID:integer;<br> pt:TPOINT;<br>begin<br> if msg.Msg = WM_TRAYNOTIFY then<br> begin<br> {<br> 在通知消息中,wParam参数为图标的uID,<br> lParam参数为鼠标事件的类型。<br> }<br> iconID := msg.WParam;<br> //获取鼠标的在屏幕上的位置<br> GetCursorPos(pt);<br><br> //通知消息的处理的基本框架结构如下:<br> case msg.lParam of<br> WM_LBUTTONDOWN:<br> begin<br> //鼠标右键被按下<br> end;<br> WM_RBUTTONDOWN:<br> begin<br> //鼠标左键被按下<br> end;<br> WM_LBUTTONUP:<br> begin<br> //释放鼠标左键<br> end;<br> WM_RBUTTONUP:<br> begin<br> //释放鼠标右键<br> end;<br> WM_MOUSEMOVE:<br> begin<br> //鼠标在图标上移动<br> end;<br> WM_LBUTTONDBLCLK:<br> begin<br> //鼠标左键双击<br> end;<br> WM_RBUTTONDBLCLK:<br> begin<br> //鼠标右键双击<br> end;<br> end; //end case<br> end<br> else//调用父类的WndProc方法处理其它消息<br> inherited;<br>end;<br><br>end.<br>有些东西,你就自己加好了。希望这些对你有用了。<br>上面只是我做的小试验,你看看。行不行了。