動畫關(guān)閉窗口的示例
發(fā)表時(shí)間:2023-08-03 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]可以像QQ一樣實(shí)現(xiàn)最小化窗口時(shí)窗口到系統(tǒng)欄的動畫效果。 Unit main; Interface Uses Windows, Messages, SysUtils, Classes, Grap...
可以像QQ一樣實(shí)現(xiàn)最小化窗口時(shí)窗口到系統(tǒng)欄的動畫效果。
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組件里的系統(tǒng)欄圖標(biāo)控件
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); //產(chǎn)生窗體從系統(tǒng)工作區(qū)中進(jìn)入或出來的動態(tài)效果子過程
Public
{ Public declarations }
End;
Var
FormMain: TFormMain;
Implementation
{$R *.DFM}
Procedure TFormMain.FormShow(Sender: TObject);
Begin
ShowWindow(Application.Handle, SW_HIDE);//消除任務(wù)欄顯示
End;
Procedure TFormMain.OnMinCmd(Var Message: Tmessage);
Begin
If (Message.WParam = SC_MINIMIZE) Then //如果是最小化消息
Begin
TrayIcon1.Active := True; //顯示圖標(biāo)
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.