各位,我将源码贴于此,请多多指教,谢谢!<br><br>unit clock;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls,<br> Forms, Dialogs,shellapi, ExtCtrls, ComCtrls, StdCtrls, Menus;<br>const<br> WM_TRAYNOTIFY=WM_USER+1;//定义通知消息<br><br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> StatusBar1: TStatusBar;<br> Label1: TLabel;<br> Label2: TLabel;<br> Label3: TLabel;<br> Edit1: TEdit;<br> Edit2: TEdit;<br> Edit3: TEdit;<br> Button1: TButton;<br> Button2: TButton;<br> CheckBox1: TCheckBox;<br> CheckBox2: TCheckBox;<br> Bevel1: TBevel;<br> PopupMenu1: TPopupMenu;<br> N1: TMenuItem;<br> N3: TMenuItem;<br> N4: TMenuItem;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure N4Click(Sender: TObject);<br> procedure N1Click(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> nd:notifyicondata;<br> hs:longword;<br> formhide:boolean;<br> information:string;<br> c_already_run_time:string;<br> c_current_time:string;<br><br> implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> formhide:=true;<br> hs:=loadicon(from1.handle,'mainicon');<br> //填充NotifyIconData记录型变量nd1<br> nd.cbSize := sizeof(NotifyIconData);<br> nd.Wnd := handle;<br> nd.uID := 0;<br> nd.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br> nd.uCallbackMessage := WM_TRAYNOTIFY;<br> nd.hIcon := hs;<br> StrPLCopy(nd.szTip, '成功!', 63);<br> //在任务栏状态区添加图标<br> Shell_NotifyIcon(NIM_ADD, @nd);<br> edit1.text:=timetostr(time);<br> edit2.text:=edit1.text;<br> edit3.text:='0:00:00';<br> timer1.enabled:=true;<br> end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> //将图标从任务栏状态区删除<br> Shell_NotifyIcon(NIM_DELETE, @nd);<br>end;<br><br>//处理 通知消息<br>procedure TForm1.WndProc(var Msg: TMessage);<br>var<br> IconID:integer;<br> pt:TPOINT;<br>begin<br> c_already_run_time:=' ';<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> beep;<br> formhide:=false;<br> form1.show;<br> end;<br> WM_RBUTTONDOWN:<br> begin<br> //鼠标左键被按下<br> popupmenu1.popup(pt.x,pt.y);<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> //生成已运行时间的字符串<br> if length(trim(edit3.text))<>8 then<br> begin<br> if strtoint(copy(edit3.text,1,1))<>0 then<br> c_already_run_time:=inttostr(strtoint(copy(edit3.text,1,1)))+'小时';<br> if strtoint(copy(edit3.text,3,2))<>0 then<br> c_already_run_time:=c_already_run_time+inttostr(strtoint(copy(edit3.text,3,2)))+'分';<br> if strtoint(copy(edit3.text,6,2))<>0 then<br> c_already_run_time:=c_already_run_time+inttostr(strtoint(copy(edit3.text,6,2)))+'秒';<br> end<br> else<br> begin<br> if strtoint(copy(edit3.text,1,2))<>0 then<br> c_already_run_time:=copy(edit3.text,1,2);<br> if strtoint(copy(edit3.text,4,2))<>0 then<br> c_already_run_time:=c_already_run_time+copy(edit3.text,4,2);<br> if strtoint(copy(edit3.text,7,2))<>0 then<br> c_already_run_time:=c_already_run_time+copy(edit3.text,7,2);<br> end;<br> //修改提示信息<br> information:='成功啦!您的电脑是 '+edit1.text+' 打开的,已经运行了:'<br> +c_already_run_time;<br> StrPLCopy(nd.szTip, information, 100);<br> Shell_NotifyIcon(NIM_MODIFY, @nd);<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>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> if formhide=true then form1.hide;<br> timer1.interval:=1000;<br> edit2.text:=timetostr(time);<br> edit3.text:=timetostr(strtotime(edit2.text)-strtotime(edit1.text));<br> //整点报时<br> if (length(edit2.text)=8) and (checkbox1.checked=true) and (strtoint(copy(edit2.text,4,2))=0) and (strtoint(copy(edit2.text,7,2))=0) then<br> showmessage('现在时间:'+edit2.text);<br> if (length(edit2.text)=7) and (checkbox1.checked=true) and (strtoint(copy(edit2.text,3,2))=0) and (strtoint(copy(edit2.text,6,2))=0)then<br> showmessage('现在时间:'+edit2.text);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> form1.Hide;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> application.Terminate;<br>end;<br><br>procedure TForm1.N4Click(Sender: TObject);<br>begin<br> application.terminate;<br>end;<br><br>procedure TForm1.N1Click(Sender: TObject);<br>begin<br> //messagebox('希望您多多指教。(作者:彭滔)','关于闹钟',mb_OK,1);<br> beep;<br> Application.MessageBox(<br> '希望您多多指教,不胜感激。(snookerfan)',<br> '关于闹钟',<br> mb_ok);<br>end;<br><br>end.