如何才能像其它软件一样在最小化是在系统托盘上出现一个可控制的图标?
请高手指教,不胜感激~!~

解决方案 »

  1.   

    Samples页面下有这个组件吧!?
      

  2.   

    unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,shellapi;const MY_MESSAGE = WM_USER + 100;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormPaint(Sender: TObject);
      private
        procedure OnIconNotify(var Message: TMessage);
                      message MY_MESSAGE;
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.dfm}
    procedure TForm1.OnIconNotify(var Message: TMessage);
    var
     Busy: Boolean;
    begin
    busy:=false;
    if not Busy then
      begin
        busy :=   true;
        if Message.LParam=WM_LBUTTONDOWN then
          if Application.MessageBox('Are you sure','Exit',
                        MB_YESNO)=IDYES then Close;
        Busy := false;
      end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    var
      nid: TNotifyIconData;
    begin
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.Wnd := Handle; // 主窗口句柄
      nid.uID :=1; // 内部标识,可设为任意数
      nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
      nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
      nid.szTip := 'This is a test application'; // 提示字符串
      nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
      nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?
      if not Shell_NotifyIcon(NIM_ADD,@nid) then
        begin
          ShowMessage('Failed!');
          Application.Terminate;
        end;
    {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
      SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    var
      nid: TNotifyIconData;
    begin
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.uID := 1; //内部标识,与加入小图标时的数一致
      nid.Wnd := Handle; //主窗口句柄
      Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
      Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
    end;
    procedure TForm1.FormPaint(Sender: TObject);
    begin
      Hide;
    end;
    end.
      

  3.   

    uses
      ShellAPI;
    const
      CICON_ID = 1;
      NIM_CALLBACKMSG = WM_USER + 100;  procedure InstallNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
        const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string); stdcall;
      procedure ModifyNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
        const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string); stdcall;
      procedure UninstallNotifyIcon(const ParentWnd: HWND; const AIconID: UINT); stdcall;implementationprocedure InstallNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
      const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string);
    var
      NID: TNotifyIconData;
      uLen: Byte;
    begin
      if Length(ATip) > 64 then
        uLen := 64
      else
        uLen := Length(ATip);  NID.cbSize := SizeOf(TNotifyIconData);
      NID.Wnd := ParentWnd;
      NID.uID := AIconID;
      NID.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      NID.uCallbackMessage := ACallBackMsg;
      NID.hIcon := AIcon.Handle;
      Move(Pointer(ATip)^, NID.szTip, uLen);  Shell_NotifyIcon(NIM_ADD, @NID);
    end;procedure ModifyNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
      const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string);
    var
      NID: TNotifyIconData;
      uLen: Byte;
    begin
      if Length(ATip) > 64 then
        uLen := 64
      else
        uLen := Length(ATip);  NID.cbSize := SizeOf(TNotifyIconData);
      NID.Wnd := ParentWnd;
      NID.uID := AIconID;
      NID.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      NID.uCallbackMessage := ACallBackMsg;
      NID.hIcon := AIcon.Handle;
      Move(Pointer(ATip)^, NID.szTip, uLen);  Shell_NotifyIcon(NIM_MODIFY, @NID);
    end;procedure UninstallNotifyIcon(const ParentWnd: HWND; const AIconID: UINT);
    var
      NID: TNotifyIconData;
    begin
      NID.cbSize := SizeOf(TNotifyIconData);
      NID.Wnd := ParentWnd;
      NID.uID := AIconID;  Shell_NotifyIcon(NIM_DELETE, @NID);
    end;
      

  4.   

    下载一个控件叫"CoolTrayIcon"的,他能帮你
      

  5.   

    delphi自己有这个控件,很简单。TayIcon