procedure AnimateForm(Form: TForm);
var
FDesktopCanvas: TCanvas;
FDesktopHandle: Hwnd;
FDesktopBitmap: TPicture;
SRect: TRect;
aPos1,aPos2,
N,FLeft,FTop: Integer;
KLeft,KTop,KRight,KBottom,
FStep: Double;
begin
FDesktopHandle := 0;
FDesktopBitmap := TPicture.Create;
FDesktopCanvas := TCanvas.Create;
FDesktopBitmap.Bitmap.Width := Screen.Width;
FDesktopBitmap.Bitmap.Height := Screen.Height;
FLeft := Form.Left;
FTop := Form.Top;
if Form.Position = poScreenCenter then
begin
if Form.FormStyle = fsMDIChild then
begin
FLeft := (Application.MainForm.ClientWidth - Form.Width) div 2;
FTop := (Application.MainForm.ClientHeight - Form.Height) div 2;
end else
begin
FLeft := (Screen.Width - Form.Width) div 2;
FTop := (Screen.Height - Form.Height) div 2;
end;
if FLeft < 0 then FLeft := 0;
if FTop < 0 then FTop := 0;
end
else if Form.Position = poDesktopCenter then
begin
if Form.FormStyle = fsMDIChild then
begin
FLeft := (Application.MainForm.ClientWidth - Form.Width) div 2;
FTop := (Application.MainForm.ClientHeight - Form.Height) div 2;
end else
begin
FLeft := (Screen.DesktopWidth - Form.Width) div 2;
FTop := (Screen.DesktopHeight - Form.Height) div 2;
end;
if FLeft < 0 then FLeft := 0;
if FTop < 0 then FTop := 0;
end;
FDesktopCanvas.Handle := GetWindowDC(FDesktopHandle);
SendMessage(FDesktopHandle, WM_PAINT, FDesktopCanvas.Handle, 0);
SRect := Rect(0, 0, Screen.Width, Screen.Height);
FDesktopBitmap.Bitmap.Canvas.CopyRect(SRect,FDesktopCanvas,SRect);
FDesktopCanvas.Brush.Color := clBtnFace;
FDesktopCanvas.Brush.Style := bsClear;
FDesktopCanvas.Pen.Color := clBlack;
FDesktopCanvas.Pen.Width := 1;
//FDesktopCanvas.Pen.Style := psDot;
N := Form.Width div 32;
if N<=0 then
N := 4;
aPos1 := (Form.Width div 2)+FLeft;
aPos2 := (Form.Height div 2)+FTop;
KTop := aPos2; KLeft := aPos1;
KRight := aPos1; KBottom := aPos2;
FStep := Form.Height / Form.Width;
while KLeft>FLeft do
begin
KLeft := KLeft - N;
KTop := KTop - FStep*N;
KRight := KRight + N;
KBottom := KBottom + FStep*N;
if (KLeft<FLeft) or (KTop<FTop+1) then Break;
Sleep(10); //延时
FDesktopCanvas.Rectangle(Trunc(KLeft),Trunc(KTop),Trunc(KRight),Trunc(KBottom));
BitBlt(FDesktopCanvas.Handle,Trunc(KLeft)+2,Trunc(KTop)+2,
Trunc(KRight-KLeft)-4,Trunc(KBottom-KTop)-4,
FDesktopBitmap.Bitmap.Canvas.Handle,Trunc(KLeft)+2,Trunc(KTop)+2,SRCCOPY);
end;
{BitBlt(FDesktopCanvas.Handle,FLeft,FTop,Width,Height,
FDesktopBitmap.Canvas.Handle,FLeft,FTop,SRCCOPY);}
ReleaseDC(0, FDesktopCanvas.Handle);
FDesktopBitmap.Free;
FDesktopCanvas.Free;
end;
在FormShow中AnimateForm(Self)就可以了