你想实现系统托盘的效果是吗?如果是你下一个abc控件包,里头有这样的控件最小化应用程序
application.Minimize;
恢复视窗 Application.Restore;

解决方案 »

  1.   

    2。你可以用TrayIcon1控件, 在它的实现点击PopupMenu属性加入你定义的
    弹出菜单,这个控件在很多的控件包里有。
      

  2.   

    一个托盘加钩子的例子:
    unit Keyspymain;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Menus, StdCtrls, Buttons, ShellApi;function BeginKeySpy: Bool; external 'GetIntoFile.dll';
    function EndKeySpy: Bool; external 'GetIntoFile.dll';const
      icon_ID= 1;
      WM_BARICON= WM_USER + 200;type
      Tfrmmain = class(TForm)
        bbtnbeginhook: TBitBtn;
        bbtnendhook: TBitBtn;
        pmhook: TPopupMenu;
        bbtnexit: TBitBtn;
        nbeginhook: TMenuItem;
        nendhook: TMenuItem;
        N3: TMenuItem;
        nabout: TMenuItem;
        N5: TMenuItem;
        nexit: TMenuItem;
        ngettext: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure bbtnbeginhookClick(Sender: TObject);
        procedure bbtnendhookClick(Sender: TObject);
        procedure bbtnexitClick(Sender: TObject);
        procedure nbeginhookClick(Sender: TObject);
        procedure nendhookClick(Sender: TObject);
        procedure nexitClick(Sender: TObject);
      private
        { Private declarations }
    //    Nid: TNotifyIconData;
        NormalIcon: TIcon;
        Nid: PNotifyIconData;
    //    procedure Minimize(var Msg: TMessage); Message WM_SYSCOMMAND;
        procedure Minimize(Sender: TObject);
        procedure IconOperate(var Msg: TMessage); Message WM_BARICON;
      public
        { Public declarations }
      end;var
      frmmain: Tfrmmain;
      HndRunned: THandle;implementation{$R *.DFM}procedure Tfrmmain.Minimize(Sender: TObject);
    begin
         Nid:= New(PNotifyIconDataA);
         Nid.cbSize:= SizeOf(Nid);
         Nid.Wnd:= Handle;
         Nid.uID:= icon_id;
         Nid.uFlags:= Nif_icon or Nif_message or Nif_tip;
         Nid.uCallbackMessage:= WM_BARICON;
         Nid.hIcon:= NormalIcon.Handle;
         StrCopy(Nid.szTip, PChar(Caption));
         Application.Minimize;
         ShowWindow(Application.Handle,sw_hide);
         Shell_NotifyIcon(Nim_add, Nid);
         Dispose(Nid);
    end;//<<another way to realize the minimize, but not good>>//
    {procedure Tfrmmain.Minimize(var Msg: TMessage);
    begin
      if Msg.wParam = SC_MINIMIZE then
         begin
         Nid:= New(PNotifyIconDataA);
         Nid.cbSize:= SizeOf(Nid);
         Nid.Wnd:= Handle;
         Nid.uID:= icon_id;
         Nid.uFlags:= Nif_icon or Nif_message or Nif_tip;
         Nid.uCallbackMessage:= WM_BARICON;
         Nid.hIcon:= NormalIcon.Handle;
         StrCopy(Nid.szTip, PChar(Caption));
         Application.Minimize;
         ShowWindow(Application.Handle,sw_hide);
         Shell_NotifyIcon(Nim_add, Nid);
         Dispose(Nid);
     //   SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
     //    frmmain.Visible:= False;
         end
      else
        //如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。
        DefWindowProc(Handle, Msg.Msg, Msg.wParam, Msg.lParam);
    end;}procedure Tfrmmain.IconOperate(var Msg: TMessage);
    var
      pt: TPoint;
    begin
      if Msg.lParam = WM_LBUTTONDOWN then
         begin
         Nid:= New(PNotifyIconDataA);
         Nid.cbSize:= SizeOf(Nid);
         Nid.Wnd:= Handle;
         Nid.uID:= icon_ID;
         Nid.uFlags:= Nif_icon or Nif_message or Nif_tip;
         Nid.uCallbackMessage:= WM_BARICON;
         Nid.hIcon:= Normalicon.Handle;
         StrCopy(Nid.szTip, PChar(Caption));
         Shell_NotifyIcon(Nim_Delete, Nid);
         Dispose(Nid);
         Showwindow(Application.Handle,sw_show);
         Application.Restore;
     //    frmmain.Visible:= True;
         end;
      if Msg.lParam = WM_RBUTTONDOWN then
         begin
         GetCursorPos(pt);
         SetForegroundWindow(Handle);            //needed
         pmhook.Popup(pt.x, pt.y);
         end;
    end;procedure Tfrmmain.FormCreate(Sender: TObject);
    begin
      NormalIcon:= frmmain.Icon;
      Application.Title:= Caption;
      Application.OnMinimize:= Minimize;
    end;procedure Tfrmmain.bbtnbeginhookClick(Sender: TObject);
    begin
      if BeginKeySpy then
         Application.MessageBox('钩子正在工作!', '标题', mb_ok);
    end;procedure Tfrmmain.bbtnendhookClick(Sender: TObject);
    begin
      if EndKeySpy then
         Application.MessageBox('钩子已结束工作!', '标题', mb_ok);
    end;procedure Tfrmmain.bbtnexitClick(Sender: TObject);
    begin
      if EndKeySpy then
         begin
         if @Nid <> Nil then       //废话
            begin
            Nid:= New(PNotifyIconDataA);
            Nid.cbSize:= SizeOf(Nid);
            Nid.Wnd:= Handle;
            Nid.uID:= icon_ID;
            Nid.uFlags:= Nif_icon or Nif_message or Nif_tip;
            Nid.uCallbackMessage:= WM_BARICON;
            Nid.hIcon:= Normalicon.Handle;
            Shell_NotifyIcon(Nim_Delete, Nid);
            Dispose(Nid);
            end;
         Application.Terminate;
         end
      else
         Application.MessageBox('请先结束钩子!', '注意', mb_ok);
    end;procedure Tfrmmain.nbeginhookClick(Sender: TObject);
    begin
      bbtnbeginhookclick(Self);
    end;procedure Tfrmmain.nendhookClick(Sender: TObject);
    begin
      bbtnendhookclick(Self);
    end;procedure Tfrmmain.nexitClick(Sender: TObject);
    begin
      bbtnexitclick(Self);
    end;initialization
      HndRunned := CreateMutex(nil, True, 'LiuXueSong');
      try
      if GetLastError = ERROR_ALREADY_EXISTS then
         Halt;
      finally
         ReleaseMutex(HndRunned);
    end;
         
    finalization
      if HndRunned <> 0 then CloseHandle(HndRunned);
    end.
      

  3.   

    TrayIcon在Sample控件组里就有啊。用起来很简单的。