好象没什么问题!把我做的贴给你看看吧!<br>implementation<br>function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external 'KERNEL32.DLL';<br><br><br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Var IconData : TNotifyIconData;<br><br>Begin<br> With IconData do Begin<br> cbSize := SizeOf(IconData);<br> Wnd := handle;<br> uID := 0;<br> uFlags := nif_Icon Or nif_Message Or nif_Tip;<br> uCallBackMessage := wm_MyCallback;<br> hIcon := Application.Icon.Handle;<br> StrCopy(szTip,'MyTrayApp');<br> End;<br> Shell_NotifyIcon(nim_Add,@IconData);<br> RegisterServiceProcess(GetCurrentProcessID, 1);//隐藏<br> <br>//RegisterServiceProcess(GetCurrentProcessID, 0);//显示<br>End;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>Var IconData : TNotifyIconData;<br>Begin<br> With IconData do Begin<br> cbSize := SizeOf(IconData);<br> Wnd := handle;<br> uID := 0;<br> uFlags := nif_Icon Or nif_Message Or nif_Tip;<br> uCallBackMessage := wm_MyCallback;<br> hIcon := Application.Icon.Handle ;<br> StrCopy(szTip,'MyTrayApp');<br> End;<br> Shell_NotifyIcon(nim_Delete,@IconData);<br>End;<br><br><br>procedure TForm1.WndProc1(var Msg: TMessage);<br>var<br> //IconID:integer;<br> Pos:TPOINT;<br>begin<br> if msg.Msg = wm_MyCallback then<br> begin<br> // iconID := msg.WParam;<br> //通知消息的处理的基本框架结构如下:<br> if msg.lParam =WM_LBUTTONDOWN then<br> if Form1.Visible then Form1.Visible := False<br> else Form1.Visible := True;<br> if msg.LParam = WM_RBUTTONDOWN<br> then<br> begin<br> GetCursorPos(Pos);<br> SetForegroundWindow(handle);<br> Form1.PopupMenu := PopupMenu1;<br> TrackPopupMenu(Form1.PopupMenu1.Handle,tpm_LeftAlign Or tpm_LeftButton,<br> Pos.X,Pos.Y,0,handle,nil);<br> // Form1.PopupMenu1.Popup(Pos.X,Pos.Y);<br> PostMessage(handle,wm_MyCallBack,0,0);<br> Form1.PopupMenu := nil;<br> end<br> else<br> inherited;<br> end;<br> <br> //调用父类的WndProc方法处理其它消息<br> end;