用delphi制作由小到大的动画窗体!

    vb 制作由小到大的窗体是很容易的,在load事件中,改变其form的大小就可以了。大体上的代码如下:

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type


Private Sub Explode(Newform As Form, Increment As Integer)
Dim Size As RECT ' setup form as rect type
GetWindowRect Newform.hwnd, Size
Dim FormWidth, FormHeight As Integer ' establish dimension variables
FormWidth = (Size.Right - Size.Left)
FormHeight = (Size.Bottom - Size.Top)
Dim TempDC
TempDC = GetDC(ByVal 0&) ' obtain memory dc for resizing
Dim Count, LeftPoint, TopPoint, nWidth, nHeight As Integer ' establish resizing variables
For Count = 1 To Increment ' loop to new sizes
nWidth = FormWidth * (Count / Increment)
nHeight = FormHeight * (Count / Increment)
LeftPoint = Size.Left + (FormWidth - nWidth) / 2
TopPoint = Size.Top + (FormHeight - nHeight) / 2
Rectangle TempDC, LeftPoint, TopPoint, LeftPoint + nWidth, TopPoint + nHeight ' draw rectangles to build form
Next Count
DeleteDC (TempDC) ' release memory resource
End Sub

Private Sub Form_Load()
Explode Me, 1000 ' open this form by number of desired increment
End Sub

本来vb也不过是在调用api,所以这样的代码完全可以迁移到delphi中,可是迁移到delphi 后,用这样的代码在

oncreate或者onshow时间中都不起作用,由于现在忙还没搞清楚怎么回事,但是可以在onactive时间中先让

form 隐藏了,再作这个效果,是可以的,方法是showwindow(form.handle,sw_hide), 不过这样不太好,换一种方法,我是这么做的:

procedure explodeForm (form:TForm;increment:real);
  var rect:TRect;
      formHeight:real;
      formWidth:real;
      i,:integer;

      rgn:HRGN;
      centerPoint:TPoint;
begin
   GetWindowRect(form.Handle,rect);

   formHeight:=rect.Bottom -rect.Top;
   formWidth:=rect.Right -rect.Left;
   centerPoint.X:=round(formWidth/2);
   centerPoint.Y:=round(formHeight/2);
     for i:=1 to round(increment) do
     begin
        nwidth:=round(formWidth*i/increment);
        rgn:=createRectRgn(centerPoint.X-nwidth,centerPoint.Y-nwidth,centerPoint.X+nwidth,centerPoint.Y +nwidth);
        setWindowRgn(form.Handle,rgn,true);
        showWindow(form.Handle,SW_show);
        deleteobject(rgn);
     end;

end;

然后在oncreate事件中调用就好了:explodeForm(form1,60); 比vb那个效果好一点,当然这格代码放在vc的

oninitdialog事件中,照样实现vc的窗体由小到大!

至于rectangle为啥没起作用,我还得查查,先交了活!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值