最好给出自己亲自写的 ,可以正常运行的源代码,不要百度的东西?

解决方案 »

  1.   

    在托盘组件的 PopupMenu属性上关联一个TPopupMenu组件就行了啊
      

  2.   

    你可用Raize组件的RzTrayIcon控件就可以轻松实现
      

  3.   

    如果是有窗体的App,那么添加一个PopMenu,在托盘里面调用就行了
      

  4.   

    这是我2005年初写的一段代码。后来少用,而且又有组件可以实现该功能,看到你的问题,我拿出来整理了下,在Delphi 2010编译通过。TrayIcon 单元代码:
    unit TrayIcon;interfaceuses
      Windows, Messages, ShellAPI;const
      Nux: Cardinal = 100;
      MouseMsg = WM_USER+1;type
      TTrayIcon = class
      private
        Ntida: TNotifyIcondataA;
      public
        constructor Create(MainHandle: HWND; IconHandle: HWND);
        procedure InstallIcon;
        procedure UnInstallIcon;
      end;implementation{ TTrayIcon }constructor TTrayIcon.Create(MainHandle, IconHandle: HWND);
    begin
      with Ntida do
      begin
        cbSize := SizeOf(TNotifyIcondataA);
        Wnd := MainHandle;
        uID := Nux;
        uFlags := NIF_ICON+NIF_TIP+NIF_MESSAGE;
        uCallbackMessage := MouseMsg;
        hIcon := IconHandle;
        szTip := ' www.HantonInfo.com ';
      end;
    end;procedure TTrayIcon.InstallIcon;
    begin
      Shell_NotifyIconA(NIM_ADD, @Ntida);
    end;procedure TTrayIcon.UnInstallIcon;
    begin
      Shell_NotifyIconA(NIM_DELETE, @Ntida);
    end;end.项目主窗口代码:
    unit Main;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ShellAPI, Menus, TrayIcon, StdCtrls;const
      Nux: Cardinal = 100;
      MouseMsg = WM_USER+1;type
      TfrmMain = class(TForm)
        PopupMenu1: TPopupMenu;
        est11: TMenuItem;
        est21: TMenuItem;
        meuExit: TMenuItem;
        mmoIntroduction: TMemo;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure meuExitClick(Sender: TObject);
      private
        { Private declarations }
        //*系统托盘鼠标事件*
        procedure OnIconNotify(var msg: TMessage); message MouseMsg;
      public
        { Public declarations }
      end;var
      frmMain: TfrmMain;
      TrayIcon: TTrayIcon;implementation{$R *.dfm}procedure TfrmMain.meuExitClick(Sender: TObject);
    begin
      Close;
    end;procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      TrayIcon.UnInstallIcon;
      TrayIcon.Free;
    end;procedure TfrmMain.FormCreate(Sender: TObject);
    begin
      TrayIcon := TTrayIcon.Create(Self.Handle, Application.Icon.Handle);
      TrayIcon.InstallIcon;
    end;procedure TfrmMain.OnIconNotify(var msg: TMessage);
    var
      MousePoint: TPoint;
    begin
      inherited;
      //鼠标右键点击图标则显示弹出菜单
      if msg.LParam = WM_RBUTTONUP then
      begin
        GetCursorPos(MousePoint);
        //*激活指定窗口*
        SetForegroundWindow(Self.Handle);
        PopupMenu1.Popup(MousePoint.X, MousePoint.Y);
      end;
      //鼠标左键点击图标则显示窗体
      if msg.LParam = WM_LBUTTONUP then
      begin
        //*让窗口显示在最前方*
        SetWindowPos(Self.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
        //*取消窗口最前属性*
        SetWindowPos(Self.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
      end;
      msg.Result := 0;
    end;end.
    主窗口中我测试时加了个Memo组件,命名为mmoIntroduction.其实就是引用TrayIcon单元,然后在加一个系统托盘事件实现具体的功能。
    希望能帮到你。