不只道我理解的对不对 你可以试试 <br>这是工程文件<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>program Project2;<br><br>uses<br> Forms,windows,<br> Units in 'Units.pas' {Form1};<br><br>{$R *.RES}<br>var<br>fhandle : Thandle;<br>begin<br> fhandle:=findwindow(0,'sx');<br> if fhandle =0 then<br> begin<br> Application.Initialize;<br> Application.Title := 'sx';<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br><br> end<br> else<br> begin<br> showwindow(fhandle,SW_RESTORE);<br> setforegroundwindow(fHandle )<br><br> end;<br> end.<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>这是单元文件<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,shellapi,<br> Menus, StdCtrls;<br><br>const<br> MY_MESSAGE = WM_USER + $100;<br>type<br> TForm1 = class(TForm)<br> PopupMenu1: TPopupMenu;<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br><br> procedure OnIconNotify(var message:Tmessage);message MY_MESSAGE;<br> procedure NotifyCreate;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> nid:TNotifyIconData;<br> messageid:dword;<br><br><br>implementation<br><br>{$R *.DFM}<br><br>{ TForm1 }<br><br>procedure TForm1.NotifyCreate;<br>var<br>nid:Tnotifyicondata;<br>begin<br>nid.cbsize:=sizeof(nid);<br>nid.wnd:= form1.Handle ;<br>nid.uID := 1;<br>nid.hIcon :=application.Icon.Handle ;<br>nid.szTip:='hhhh';<br>nid.uCallbackMessage :=MY_MESSAGE;<br>nid.uFlags :=NIF_ICON or NIF_TIP or NIF_MESSAGE;<br>if not shell_notifyicon(NIM_ADD,@nid) then begin<br> showmessage('出错了');<br> application.Terminate ;<br> end;<br>setwindowlong(application.handle,GWL_ExSTYLE,WS_EX_TOOLWINDOW);<br>end;<br><br><br><br>procedure TForm1.OnIconNotify(var message: Tmessage);<br>const<br>busy:boolean = false;<br>var<br>mypt:tpoint;<br>begin<br>inherited;<br>if not busy then<br> begin<br> busy:=true;<br> if message.LParam = WM_LBUTTONDOWN then<br> begin<br> application.Restore;<br> setforegroundwindow(application.Handle );<br> end<br> else<br> if message.LParam = WM_RBUTTONDOWN then<br> begin<br> getcursorpos(mypt);<br> popupmenu1.popup(mypt.x,mypt.y);<br> end;<br> message.Result:=0;<br> end;<br><br> busy:= false;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br><br>form1.NotifyCreate ;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>shell_notifyicon(nim_delete,@nid);<br>end;<br><br><br>end.<br>