这是我写的一个小服务器的控制程序中用的。<br><br>{ ** 放入托盘程序 ** }<br>procedure TMainFrm.AddIco;<br>var<br> nid: TNotifyIconData;<br>begin<br> nid.cbSize := sizeof(nid);<br> nid.Wnd := Handle;<br> nid.uID := 0;<br> nid.hIcon := Application.Icon.Handle;<br> nid.szTip := '远程数据交换服务器 1.2';<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<br> begin<br> ShowMessage('服务程序进驻失败!');<br> Application.Terminate;<br> end;<br>end;<br><br>{ ** 取消托盘程序 ** }<br>procedure TMainFrm.DelIco;<br>var<br> nid: TNotifyIconData;<br>begin<br> nid.cbSize := sizeof(nid);<br> nid.uID := 0;<br> nid.Wnd := Handle;<br> Shell_NotifyIcon(NIM_DELETE, @nid);<br>end;<br><br>{ ** 弹出托盘菜单 ** }<br>procedure TMainFrm.OnIconNotify(var Message: TMessage);<br>const<br> Busy: Boolean = false;<br>var<br> p: TPoint;<br>begin<br> if not Busy then begin<br> Busy := true;<br> if Message.LParam=WM_RBUTTONDOWN then<br> begin<br> GetCursorPos(p);<br> PopupMenu.Popup(p.x, p.y);<br> end;<br> Busy := false;<br> end;<br>end;<br>