昨天我刚刚写了这个程序。<br>看看我的代码吧。(支持 nt)<br>我还接获了窗口极小化的消息。你可以自己修改。<br>需包含 shellAPI 单元。<br><br>const<br> WM_TRAYNOTIFY = WM_USER + 1234; //自定义trayICON消息<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> PopupMenu1: TPopupMenu;<br> Show1: TMenuItem;<br> Exit1: TMenuItem;<br> About1: TMenuItem;<br> procedure Button1Click(Sender: TObject);<br> procedure Show1Click(Sender: TObject);<br> procedure Exit1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> tnd: NOTIFYICONDATA;<br> procedure MyWindowProc(var Message: TMessage);<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.MyWindowProc(var Message: TMessage);<br>var<br> p:tpoint;<br>begin<br> case Message.Msg of<br> WM_TRAYNOTIFY: begin<br> case Message.LParam of<br> WM_RBUTTONDOWN: begin //鼠标右健click<br> GetCursorPos(p);<br> PopupMenu1.Popup(p.x, p.y);<br> end;<br> WM_LBUTTONDBLCLK: // 左键双击<br> Show1.Click;<br> end;<br> end;<br> WM_SYSCOMMAND: begin<br> if (Message.WParam = SC_MINIMIZE) then // 如果是极小化<br> Button1.Click<br> else<br> Dispatch(Message);<br> end<br> else<br> Dispatch(Message);<br> end;<br>end;<br><br>// 隐藏窗口,建立TrayICON<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> tnd.cbSize:= sizeof(NOTIFYICONDATA);<br> tnd.Wnd:= self.Handle;<br> tnd.uID:= 0;<br> tnd.uFlags:= NIF_MESSAGE or NIF_ICON or NIF_TIP;<br> tnd.uCallbackMessage:= WM_TRAYNOTIFY;<br> tnd.hIcon:= self.Icon.Handle;<br> tnd.szTip:= '耙子的例子 93611.yeah.net';<br> if Shell_notifyIcon(NIM_ADD, @tnd) then<br> begin<br> Self.Hide;<br> end;<br>end;<br><br>// Popup show 菜单<br>procedure TForm1.Show1Click(Sender: TObject);<br>begin<br> Self.Show;<br> Shell_notifyIcon(NIM_DELETE, @tnd);<br>end;<br><br>procedure TForm1.Exit1Click(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> // 替换 TFrom 的 WindowProc<br> WindowProc:= MyWindowProc;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> Shell_NotifyIcon(NIM_DELETE, @TND);<br>end;<br><br>