三度网教程:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

动画关闭窗口的示例

时间:2023-12-19作者:未知来源:三度网教程人气:


可以像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.

关键词:  动画关闭窗口的示例





Copyright © 2012-2018 三度网教程(http://www.3du8.cn) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版