请问下托盘怎么做,详细点,谢谢。

解决方案 »

  1.   

    随便一搜就一大把
    http://topic.csdn.net/t/20060822/12/4966829.html
      

  2.   

    delphi2006及以上版本自带了托盘空间,低版本的可以安装第三方的控件
      

  3.   


    unit   Unit1;   
        
    interface   
        
    uses   
          Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,   
          Dialogs,   StdCtrls,shellapi,   Menus,   AppEvnts,Registry;   
          const   
          mousemsg   =   wm_user   +   1;   //自定义消息,用于处理用户在图标上点击鼠标的事件   
          iid   =   100;   //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用   
      type   
          TForm1   =   class(TForm)   
              Button1:   TButton;   
              PopupMenu1:   TPopupMenu;   
              N1:   TMenuItem;   
              ApplicationEvents1:   TApplicationEvents;   
              procedure   FormCreate(Sender:   TObject);   
              procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);   
              procedure   Button1Click(Sender:   TObject);   
              procedure   ApplicationEvents1Minimize(Sender:   TObject);   
              procedure   FormShow(Sender:   TObject);   
          private   
            procedure   mousemessage(var   message:   tmessage);   message   mousemsg;   
              {   Private   declarations   }   
          public   
              {   Public   declarations   }   
          end;   
        
      var   
          Form1:   TForm1;   
          ntida:TNotifyIcondataA;   //用于增加和删除系统状态图标   
        implementation   
        
      {$R   *.dfm}   
        
      procedure   TForm1.FormCreate(Sender:   TObject);   
      begin   
            ntida.cbSize   :=   sizeof(tnotifyicondataa);   //指定ntida的长度   
          ntida.Wnd   :=   handle;   //取应用程序主窗体的句柄   
          ntida.uID   :=   iid;   //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使   
          ntida.uFlags   :=   nif_icon   +   nif_tip   +   
              nif_message;   //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效   
          ntida.uCallbackMessage   :=   mousemsg;   
          //指定的窗口消息   
        //   ntida.hIcon   :=   Application.Icon.handle;   
          //指定系统状态栏显示应用程序的图标句柄   
          ntida.szTip   :=   'Icon';   
          //当鼠标停留在系统状态栏该图标上时,出现该提示信息   
          shell_notifyicona(NIM_ADD,   @ntida);   
          //在系统状态栏增加一个新图标   
      end;   
        
        
      procedure   TForm1.mousemessage(var   message:   tmessage);   
      var   
          mousept:   TPoint;   //鼠标点击位置   
      begin   
          inherited;   
          if   message.LParam   =   wm_rbuttonup   then   begin   //用鼠标右键点击图标   
                  getcursorpos(mousept);   //获取光标位置   
                  popupmenu1.popup(mousept.x,   mousept.y);   
                  //在光标位置弹出选单   
              end;   
          if   message.LParam   =   wm_lbuttonup   then   begin   //用鼠标左键点击图标   
              {     //显示应用程序窗口   
                  ShowWindow(Handle,   SW_SHOW);   
                  //在任务栏上显示应用程序窗口   
                  ShowWindow(Application.handle,   SW_SHOW);   
                  SetWindowLong(Application.Handle,   GWL_EXSTYLE,   
                      not   (GetWindowLong(Application.handle,   GWL_EXSTYLE)   
                      or   WS_EX_TOOLWINDOW   and   not   WS_EX_APPWINDOW));       }   
              end;   
          message.Result   :=   0;   
      end;   
        
      procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);   
      begin   
          Action   :=   caNone;   //不对窗体进行任何操作     
          ShowWindow(Handle,   SW_HIDE);   //隐藏主窗体   
          //隐藏应用程序窗口在任务栏上的显示   
          ShowWindow(Application.Handle,   SW_HIDE);   
          SetWindowLong(Application.Handle,   GWL_EXSTYLE,   
              not   (GetWindowLong(Application.handle,   GWL_EXSTYLE)   
              or   WS_EX_TOOLWINDOW   and   not   WS_EX_APPWINDOW));   
      end;   
        
      procedure   TForm1.Button1Click(Sender:   TObject);   
      begin   
            ntida.cbSize   :=   sizeof(tnotifyicondataa);   
          ntida.wnd   :=   handle;   
          ntida.uID   :=   iid;   
          ntida.uFlags   :=   nif_icon   +   nif_tip   +   nif_message;   
          ntida.uCallbackMessage   :=   mousemsg;   
          ntida.hIcon   :=   Application.Icon.handle;   
          ntida.szTip   :=   'My Application Icon';   
          shell_notifyicona(NIM_DELETE,   @ntida);   
          //删除已有的应用程序图标   
              Application.Terminate;   
          end;   
        
      end.
      

  4.   

    Delphi自带的TrayIcon就OK,别说你用的旧版D7之类的
      

  5.   

    如果用d7 ,raize包里面也挺好的.
      

  6.   


    [code=Delphi(Pascal)]
      在private中:   
      procedure   WMSysCommand(var   wMessage:   TWMSysCommand);   message   WM_SysCommand;   
        
      在implementation中:     procedure   TForm1.WMSysCommand(var   wMessage:   TWMSysCommand);   
      begin   
          if wmessage.CmdType=SC_CLOSE then
           begin   
            //进行自己的处理
           end    
          else   
          begin   
            inherited;
           end;   
      end;   
        [/code]
      

  7.   

    招聘 delphi 程序员(人数:2)
     毕业两年以上
     两年以上 delphi 工作经验
     熟悉 sql server 
     sql 编写能力突出者优先联系方式:
     深圳中普达科技有限公司
     0755 86170837
     请将简历发至 [email protected]
      

  8.   

    可以直接使用的代码{***************************
     *  单元名称: 托盘图标组件
     *  编写人员:毛子兵
     *  编写日期: 2004.10.30
     **************×************}
    unit JrTrayIcon;interfaceuses
      SysUtils, Classes, Windows, Forms, Graphics, Controls, ExtCtrls,
      Messages, Menus, ShellAPI;const
      WM_NOTIFYICON = WM_USER + 1;type 
      TJrTrayIcon = class(TComponent)
      private
        { Private declarations }
        FHideMainForm: Boolean;
        FMainWin: TForm;
        FWindowHandle: HWND;
        FActive: Boolean;
        FAnimate: Boolean;
        FAnimateInterval: Integer;
        FImages: TImageList;
        FCurrentImageIndex: Integer;
        FTimer: TTimer;
        FIcon: TIcon;
        FOriginalIcon: TIcon;
        FHint: String;
        FShowDesigning: Boolean;
        FPopupMenu: TPopupMenu;
        FOnClick: TNotifyEvent;
        FOnDblClick: TNotifyEvent;
        FOnRightClick: TNotifyEvent;
        FIconData: TNotifyIconData;
        procedure SetHint(const Value: String);
        procedure SetIcon(const Value: TIcon);
        procedure SetActive(const Value: Boolean);
        procedure SetAnimate(const Value: Boolean);
        procedure SetAnimateInterval(const Value: integer);
        procedure SetHideMainForm(const Value: Boolean);
        procedure SetShowDesigning(const Value: Boolean);
        procedure ChangeIcon(Sender: TObject);
        procedure DoRightClick(Sender: TObject);    procedure WndProc(var Msg: TMessage);    procedure FillDataStructure;
        function AddIcon: Boolean;
        function DeleteIcon: Boolean;
        function ModifyIcon: Boolean;
      protected
        { Protected declarations }
        procedure Notification(AComponent: TComponent; Operation: TOperation); override ;
      public
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;    property HideMainForm: Boolean read FHideMainForm write SetHideMainForm default False;
      published
        { Published declarations }
        property Active: Boolean read FActive write SetActive default False;
        property Animate : Boolean read FAnimate write SetAnimate default False;
        property AnimateInterval : integer read FAnimateInterval write SetAnimateInterval default 300;
        property Hint: String read FHint write SetHint;
        property Icon: TIcon read FIcon write SetIcon;
        property Images : TImageList read FImages write FImages ;
        property MainForm : TForm read FMainWin write FMainWin;
        property PopupMenu : TPopupMenu read FPopupMenu write FPopupMenu;
        property ShowDesigning : Boolean read FShowDesigning write SetShowDesigning default False;
        property OnClick     : TNotifyEvent read FOnClick write FOnClick;
        property OnDblClick  : TNotifyEvent read FOnDblClick write FOnDblClick;
        property OnRightClick: TNotifyEvent read FOnRightClick write FOnRightClick;
      end;implementation{ TJrTrayIcon }function TJrTrayIcon.AddIcon: Boolean;
    begin
      FillDataStructure;
      Result:=Shell_NotifyIcon(NIM_ADD, @FIconData);
    end;procedure TJrTrayIcon.ChangeIcon(Sender: TObject);
    var
      temp: TIcon;
    begin
      temp:=TIcon.Create;
      try
        if FCurrentImageIndex = FImages.Count - 1 then
          FCurrentImageIndex:=0
        else
          Inc(FCurrentImageIndex);
        FImages.GetIcon(FCurrentImageIndex, temp);
        SetIcon(temp);
      finally
        temp.Free;
      end;
    end;constructor TJrTrayIcon.Create(AOwner: TComponent);
    begin
      inherited;
      FWindowHandle:=Classes.AllocateHWnd(WndProc);
      FTimer:=TTimer.Create(Self);
      FTimer.Enabled:=False;
      FAnimateInterval:=300;
      FTimer.Interval:=FAnimateInterval;
      FTimer.OnTimer:=ChangeIcon;  FHideMainForm:=False;
      if AOwner is TForm then
        FMainWin:=TForm(AOwner)
      else
        FMainWin:=Nil;  FIcon:=TIcon.Create;
      FIcon.Assign(Application.Icon);
      FOriginalIcon:=TIcon.Create;
      FOriginalIcon.Assign(FIcon);  FActive:=False;
      FAnimate:=False;
      FHint:=ClassName;
      FShowDesigning:=False;
      FCurrentImageIndex:=0;
    end;function TJrTrayIcon.DeleteIcon: Boolean;
    begin
      Result:=Shell_NotifyIcon(NIM_DELETE, @FIconData);
    end;destructor TJrTrayIcon.Destroy;
    begin
      if (not(csDesigning in ComponentState) and FActive) or
         ((csDesigning in ComponentState) and FShowDesigning) then
        DeleteIcon;
      FTimer.Free;
      FIcon.Free;
      FOriginalIcon.Free;
      Classes.DeallocateHWnd(FWindowHandle);
      inherited;
    end;procedure TJrTrayIcon.DoRightClick(Sender: TObject);
    var
      MouseCo: TPoint;
    begin
      if Assigned(FPopupMenu) then begin
        GetCursorPos(MouseCo);
        SetForegroundWindow(Application.Handle);
        Application.ProcessMessages;
        FPopupmenu.Popup(Mouseco.X, Mouseco.Y);
      end;  if Assigned(FOnRightClick) then
        FOnRightClick(Sender);
    end;procedure TJrTrayIcon.FillDataStructure;
    begin
      FIconData.cbSize:=Sizeof(FIconData);
      FIconData.Wnd:=FWindowHandle;
      FIconData.uID:=0;
      FIconData.uFlags:=NIF_TIP + NIF_ICON + NIF_MESSAGE;
      FIconData.uCallbackMessage := WM_NOTIFYICON;
      FIconData.hIcon:=FIcon.Handle;
      StrPCopy(FIconData.szTip, FHint);
    end;function TJrTrayIcon.ModifyIcon: Boolean;
    begin
      FillDataStructure;
      if (not(csDesigning in ComponentState) and FActive) or
         ((csDesigning in ComponentState) and FShowDesigning) then
        Result:=Shell_NotifyIcon(NIM_MODIFY, @FIconData)
      else
        Result:=True;
    end;procedure TJrTrayIcon.Notification(AComponent: TComponent;
      Operation: TOperation);
    begin
      inherited;
      if (AComponent = FImages) and (Operation = opRemove) then begin
        FAnimate:=False;
        FImages:=Nil;
      end
      else if (AComponent = FPopupMenu) and (Operation = opRemove) then 
        FPopupMenu:=Nil;
    end;procedure TJrTrayIcon.SetActive(const Value: Boolean);
    begin
      if FActive <> Value then begin
        FActive:=Value;
        if not(csdesigning in ComponentState) and FActive then
          AddIcon
        else if not((csdesigning in ComponentState) and FShowDesigning) then
          DeleteIcon;
      end;
    end;procedure TJrTrayIcon.SetAnimate(const Value: Boolean);
    begin
      if FAnimate <> Value then begin
        FAnimate:=Value;
        if (FImages <> Nil) and (FImages.Count > 0) then
          FTimer.Enabled:=FAnimate;
        if FAnimate then begin
          FOriginalIcon.Assign(FIcon);
          FCurrentImageIndex:=0;
        end
        else
          SetIcon(FOriginalIcon);
      end;
    end;procedure TJrTrayIcon.SetAnimateInterval(const Value: integer);
    begin
      if Value > 0 then begin
        FAnimateInterval:=Value;
        FTimer.Interval:=FAnimateInterval;
      end;
    end;procedure TJrTrayIcon.SetHideMainForm(const Value: Boolean);
    begin
      if FMainWin = Nil then Exit;
      if FHideMainForm <> Value then begin
        FHideMainForm := Value;
        if FHideMainForm then
          ShowWindow(FMainWin.Handle, SW_HIDE)
        else
          ShowWindow(FMainWin.Handle, SW_SHOWNORMAL);
      end;
    end;procedure TJrTrayIcon.SetHint(const Value: String);
    begin
      if Length(Value) > 62 then
        FHint:=Copy(Value, 1, 62)
      else
        FHint:=Value;
      ModifyIcon;
    end;procedure TJrTrayIcon.SetIcon(const Value: TIcon);
    begin
      if FIcon <> Value then begin
        FIcon.Assign(Value);
        ModifyIcon;
      end;
    end;procedure TJrTrayIcon.SetShowDesigning(const Value: Boolean);
    begin
      if csdesigning in ComponentState then
        if FShowDesigning <> Value then begin
          FShowDesigning:=Value;
          if FShowDesigning then AddIcon else DeleteIcon;
        end;
    end;procedure TJrTrayIcon.WndProc(var Msg: TMessage);
    begin
      with Msg do
        if (Msg = WM_NOTIFYICON) then begin
          case lParam of
            WM_LBUTTONDBLCLK: if Assigned(FOnDblClick) then FOnDblClick(Self);
            WM_LBUTTONUP    : if Assigned(FOnClick)then FOnClick(Self);
            WM_RBUTTONUP    : DoRightClick(Self);
          end;
        end
        else // Handle all messages with the default handler
          Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
    end;end.