请教如何实现将程序最小化到系统托盘中?程序最小化,只在系统托盘中停留。

解决方案 »

  1.   

    楼主,上盒子上搜搜trayicon这个控件,实现了托盘的多种效果,很不错.
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus, ImgList, StdCtrls, ShellAPI, ExtCtrls;const
      mymsg = wm_user + 1;
      iid = 100;type
      TForm1 = class(TForm)
        Button1: TButton;
        PopupMenu1: TPopupMenu;
        a11: TMenuItem;
        b11: TMenuItem;
        c11: TMenuItem;
        Image1: TImage;
        procedure Button1Click(Sender: TObject);
        procedure c11Click(Sender: TObject);
        procedure a11Click(Sender: TObject);
      private
        { Private declarations }
        procedure mymessage(var message:tmessage);
        message mymsg;
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      ntid: TnotifyIconDataA;implementation{$R *.dfm}//隐藏窗口,在托盘上显示图标
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ntid.cbsize := sizeof(TnotifyIconDataA);
      ntid.Wnd := Handle;
      ntid.uID := iid;
      ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
      ntid.uCallbackMessage := mymsg;
      ntid.hIcon := image1.Picture.Icon.Handle;
      ntid.szTip := 'asdf';
      shell_notifyicona(NIM_ADD,@ntid);  self.Visible := false;
    end;//处理鼠标右键,弹出菜单
    procedure TForm1.mymessage(var message:tmessage );
    var
      mypt:Tpoint;
    begin
      Inherited;
      if message.LParam = WM_RBUTTONUP then
      begin
        getCursorPos(mypt);
        PopupMenu1.Popup(mypt.X, mypt.Y);
      end;
      message.rResult := 0;
    end;procedure TForm1.c11Click(Sender: TObject);
    begin
      close;
    end;//还原窗口,托盘图标消失
    procedure TForm1.a11Click(Sender: TObject);
    begin
      ntid.cbSize := sizeof(TnotifyIconDataA);
      ntid.Wnd := Handle;
      ntid.uID := iid;
      ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
      ntid.uCallbackMessage := mymsg;
      ntid.hIcon := image1.Picture.Icon.Handle;
      ntid.szTip := 'asdf';
      shell_notifyicona(NIM_DELETE,@ntid);
      
      self.Visible := true;
    end;end.