当前位置:雨林木风下载站 > 技术开发教程 > 详细页面

动画关闭窗口的示例

动画关闭窗口的示例

更新时间:2022-05-13 文章作者:未知 信息来源:网络 阅读次数:

可以像QQ一样实现最小化窗口时窗口到系统栏的动画效果。

Unit main;

Interface

Uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   RXShell, StdCtrls;
Type TZoomDirection = (ZoomFormOpen, ZoomFormClosed);//枚举类型
Type
   TFormMain = Class(TForm)
      TrayIcon1: TRxTrayIcon;//Rx组件里的系统栏图标控件
      Label1: TLabel;
      Procedure FormShow(Sender: TObject);
    procedure TrayIcon1DblClick(Sender: TObject);
   Private
      Procedure OnMinCmd(Var Message: Tmessage); Message WM_SYSCOMMAND; //捕获消息
      Procedure FrmZoomToTray(Frm: TForm; Direction: TZoomDirection); //产生窗体从系统工作区中进入或出来的动态效果子过程
   Public
    { Public declarations }
   End;
Var
   FormMain: TFormMain;

Implementation

{$R *.DFM}

Procedure TFormMain.FormShow(Sender: TObject);
Begin
ShowWindow(Application.Handle, SW_HIDE);//消除任务栏显示
End;

Procedure TFormMain.OnMinCmd(Var Message: Tmessage);
Begin
   If (Message.WParam = SC_MINIMIZE) Then //如果是最小化消息
      Begin
         TrayIcon1.Active := True; //显示图标
         FrmZoomToTray(FormMain,ZoomFormClosed);
         FormMain.Hide; //隐藏窗体
         Exit;
      End;
   Inherited; //让窗体处理其它消息
End;

Procedure TFormMain.FrmZoomToTray(Frm: TForm; Direction: TZoomDirection);
Var
   TrayWnd: HWND;
   sClassName: Array[0..255] Of Char;
   xFrom, xTo: TRect;
Begin
   If (Direction = ZoomFormClosed) And (Frm.Visible = False) Then
      Exit;
   If (Direction = ZoomFormOpen) And (Frm.Visible = True) Then
      Exit;
   TrayWnd := FindWindow('Shell_TrayWnd', Nil);
   TrayWnd := GetWindow(TrayWnd, GW_CHILD);
   Repeat
      GetClassName(TrayWnd, @sClassName, 255);
      If StrPas(sClassName) = 'TrayNotifyWnd' Then
         Break;
      TrayWnd := GetWindow(TrayWnd, GW_HWNDNEXT);
   Until TrayWnd = 0;
   Case Direction Of
      ZoomFormOpen:
         Begin
            GetWindowRect(TrayWnd, xFrom);
            xFrom.Left := (xFrom.Right - (xFrom.Right - xFrom.Left) Div 2);
            xFrom.Right := xFrom.Left + 1;
            GetWindowRect(Frm.Handle, xTo);
            DrawAnimatedRects(Frm.Handle, IDANI_OPEN Or IDANI_CAPTION, xFrom, xTo);
         End;
      ZoomFormClosed:
         Begin
            GetWindowRect(Frm.Handle, xFrom);
            GetWindowRect(TrayWnd, xTo);
            xTo.Left := (xTo.Right - (xto.Right - xTo.Left) Div 2);
            xTo.Right := xTo.Left + 1;
            DrawAnimatedRects(Frm.Handle, IDANI_CLOSE Or IDANI_CAPTION, xFrom, xTo);
         End;
   End;
End;

procedure TFormMain.TrayIcon1DblClick(Sender: TObject);
begin
   TrayIcon1.Active := False;
   FrmZoomToTray(FormMain,ZoomFormopen);
   FormMain.Show;
end;

End.

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行