我要让最小化到任务栏的图标
现在只能通过button实现,如何修改最小化的事件呢?

解决方案 »

  1.   

    const
    //这个自定义的消息用来表示系统托盘的事件
      WM_TrayMessage=WM_USER+100; //处理托盘事件,自定义的
      procedure WMTrayMessage(var msg:Tmessage);message WM_TrayMessage;
      //捕获系统菜单的消息,用于托盘程序
      procedure WMSyscommand(var msg:Tmessage);message WM_SYSCOMMAND;//系统托盘事件函数
    procedure TForm1.WMTrayMessage(var msg:Tmessage);
    var PosPoint:Tpoint;
    begin
    //托盘自定义消息,如果是左双击同恢复窗体,并消除托盘图标
    //如果是右单击则弹出快捷菜单
     if msg.LParam=WM_LBUTTONDBLCLK then
     begin
      ShowWindow(Application.Handle,SW_SHOW);
      SendMessage(Application.Handle,WM_SYSCOMMAND,SC_RESTORE,0);
      Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
     end
     else if msg.LParam=WM_RBUTTONDOWN then
     begin
        GetCursorPos(PosPoint);
       PopupMenu2.Popup(PosPoint.X,PosPoint.Y);
     end;
    end;
    //截获系统菜单的消息,
    procedure TForm1.WMSyscommand(var msg:Tmessage);
    var placement:WINDOWPLACEMENT;
    begin
      //如果是最小化,则显示托盘,
      if msg.WParam=SC_MINIMIZE Then
        begin
         Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
         ShowWindow(Application.Handle,SW_HIDE);
         SetWindowLong(Application.Handle,GWL_EXSTYLE ,WS_EX_TOOLWINDOW);
         GetWindowPlacement(Application.Handle,@placement);
         placement.flags:=WPF_SETMINPOSITION;
         placement.ptMinPosition.x:=760;
         placement.ptMinPosition.y:=600;
         SetWindowPlacement(Application.Handle,@placement);
       end;
      inherited;
    end;
      

  2.   

    Application.Minimize
    这样最容易了
      

  3.   


    type
      ...
      private
        Procedure MyMessage(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.myMessage(var Msg: TWMSysCommand);
    begin
      if Msg.CmdType = SC_MINIMIZE then Exit; //使用最小化按鈕失效;
      inherited;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    Application.Minimize ; //最小化程序;
    end;end.