如何实现象NetAnts那样由小逐渐变大的窗体?(100分)

  • 主题发起人 主题发起人 Bomber
  • 开始时间 开始时间
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)就可以了
 
怎么写不开?
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)就可以了
 
论坛有Bug,‘<’被认为是结尾
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)就可以了
 
或直接DFW控件组
 
蚂蚁用的是AnimateWindow
AnimateWindow(Form1.Hanle,200,AW_CENTER);


AnimateWindow
The AnimateWindow function enables you to produce special effects when showing or hiding windows. There are three types of animation: roll, slide, and alpha-blended fade.

BOOL AnimateWindow(
HWND hwnd, // handle to window
DWORD dwTime, // duration of animation
DWORD dwFlags // animation type
);
Parameters
hwnd
[in] Handle to the window to animate. The calling thread must own this window.
dwTime
[in] Specifies how long it takes to play the animation, in milliseconds. Typically, an animation takes 200 milliseconds to play.
dwFlags
[in] Specifies the type of animation. This parameter can be one or more of the following values. Value Description
AW_SLIDE Uses slide animation. By default, roll animation is used. This flag is ignored when used with AW_CENTER.
AW_ACTIVATE Activates the window. Do not use this value with AW_HIDE.
AW_BLEND Uses a fade effect. This flag can be used only if hwnd is a top-level window.
AW_HIDE Hides the window. By default, the window is shown.
AW_CENTER Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
AW_HOR_POSITIVE Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_HOR_NEGATIVE Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_POSITIVE Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_NEGATIVE Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.


Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The function will fail in the following situations:

The window uses the window region.
The window is already visible and you are trying to show the window.
The window is already hidden and you are trying to hide the window.
To get extended error information, call the GetLastError function.

Remarks
You can combine AW_HOR_POSITIVE or AW_HOR_NEGATIVE with AW_VER_POSITIVE or AW_VER_NEGATIVE to animate a window diagonally.

The window procedures for the window and its child windows may need to handle any WM_PRINT or WM_PRINTCLIENT messages. Dialog boxes, controls, and common controls already handle WM_PRINTCLIENT. The default window procedure already handles WM_PRINT.

Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

See Also
Windows Overview, Window Functions, WM_PRINT, WM_PRINTCLIENT
 
发现论坛中有人“不懂装懂”,可笑!
 
好想有API函数的啊?我朋友用过,不过不支持Winnt,不知道2000里面如何?98里面成功的
 
》如何实现象NetAnts那样由小逐渐变大的窗体?

有谁可以说一下蚂蚁的这个东西是什么一回事?
 
To sbcnet:
“<”和“>”被当成 HTML 符号解释了,不是 Bug。
动画窗口很好做啊,不停地向 Canvas 上画也可以,动态改变窗口的尺寸也可以,TForm 大虾
说的 AnimateWindow 函数比较好,像这样用就可以了:
AnimateWindow(Form2.Handle,200,AW_CENTER);
下面是渐显效果,象 Window 2000 的开始菜单。
AnimateWindow(Form2.Handle,200,AW_BLEND);
 
谢谢各位!分数不多,请多包涵。
 
后退
顶部