| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 1201 人关注过本帖
标题:分享:一个完美实现窗体动态缩小最后完全消失的动画关闭效果的 UDF()
只看楼主 加入收藏
DANSON
Rank: 2
等 级:论坛游民
帖 子:197
专家分:83
注 册:2025-10-4
收藏
 问题点数:0 回复次数:8 
分享:一个完美实现窗体动态缩小最后完全消失的动画关闭效果的 UDF()

前两天刷到本坛 2012 年的一个陈年老帖:点击表单关闭按钮,如何实现像关闭金山新毒霸的关闭效果?

https://bbs.bccn.net/thread-387287-2-1.html

巧了,几年前,我也写过一个类似的 UDF ,可以完美实现窗体动态缩小最后完全消失的动画关闭效果,我的 VFP APP 中的主要任务窗体都是调用这个 UDF 进行关闭,完全可用,刚才又改良了一下,发出来和兄弟们切磋一下,抛砖引玉:

FORM_RELE_FLASH.rar (1.42 KB)
搜索更多相关主题的帖子: 缩小 关闭 效果 窗体 动态 
2026-03-15 09:59
schtg
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:USA
等 级:贵宾
威 望:67
帖 子:2558
专家分:4954
注 册:2012-2-29
收藏
得分:0 
2026-03-15 12:55
sam_jiang
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:14
帖 子:1141
专家分:1680
注 册:2021-10-13
收藏
得分:0 
有个winAPI函数可以实现这个功能的。
我把form导出到prg,可以实现放大缩小窗口直至消失。

原本可以淡入淡出的效果的,但是我的电脑不知道怎么回事,没反应。。。
函数的申明:
DECLARE integer AnimateWindow in win32api integer hwindow,integer dwtime,integer dwflags

参数说明:‌

hWnd (窗口句柄)‌:

类型:HWND
说明:指定产生动画效果的窗口句柄。调用线程必须拥有该窗口。
注意:如果线程不拥有窗口,函数会失败但 GetLastError 返回 ERROR_SUCCESS。
dwTime (动画时间)‌:

类型:DWORD
说明:指定动画持续的时间(以毫秒为单位)。完成一个动画的标准时间通常为200毫秒。
示例:设置为1000表示动画持续1秒。
dwFlags (动画标志)‌:

类型:DWORD
说明:指定动画类型,可以是一个或多个标志的组合。
主要标志包括:
方向标志‌:

AW_HOR_POSITIVE = 0x00000001:从左向右显示窗口
AW_HOR_NEGATIVE = 0x00000002:从右向左显示窗口
AW_VER_POSITIVE = 0x00000004:从上向下显示窗口
AW_VER_NEGATIVE = 0x00000008:从下向上显示窗口
效果标志‌:

AW_CENTER = 0x00000010:从中心向四周扩展(显示时)或从四周向中心收缩(隐藏时)
AW_HIDE = 0x00010000:隐藏窗口,缺省则显示窗口
AW_ACTIVATE = 0x00020000:激活窗口,与方向标志组合使用
AW_SLIDE = 0x00040000:使用滑动类型(缺省为滚动动画)
AW_BLEND = 0x00080000:使用淡出效果(仅对顶层窗口有效)



代码如下:
程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\animatewindow.scx)
*-- 父类:  form
*-- 基类:    form
*-- 时间戳:   03/14/26 01:30:00 PM
*
DEFINE CLASS form1 AS form


    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        Caption = "表单动画效果演示", ;
        Height = 16, ;
        Left = 24, ;
        Top = 12, ;
        Width = 98, ;
        Name = "Label1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 48, ;
        Left = 24, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "演示", ;
        Name = "Command1"


    PROCEDURE Load
        DECLARE integer AnimateWindow in win32api integer hwindow,integer dwtime,integer dwflags
        *animatewindow(this.HWnd,2000,BITOR(0x00040000,0x00000002,0x00020000))
        animatewindow(this.HWnd,2000,0x10+0x20000)
    ENDPROC


    PROCEDURE Destroy
        DECLARE integer AnimateWindow in win32api integer hwindow,integer dwtime,integer dwflags
        *animatewindow(this.HWnd,2000,BITOR(0x00040000,0x00000002,0x00020000))
        animatewindow(this.HWnd,2000,0x10000+0x10)
        *animatewindow(this.HWnd,2000,0x10000+0x80000) &&淡入淡出效果
    ENDPROC


    PROCEDURE command1.Click
        thisform.Hide 
        *animatewindow(thisform.HWnd,1000,BITOR(0x00040000,0x00000002,0x00020000))
        *animatewindow(thisform.HWnd,2000,0x80000+0x8)
        thisform.Load
        thisform.Show
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
2026-03-15 15:16
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:11249
专家分:43612
注 册:2014-5-20
收藏
得分:0 
淡出效果(仅对顶层窗口有效)
2026-03-15 15:35
DANSON
Rank: 2
等 级:论坛游民
帖 子:197
专家分:83
注 册:2025-10-4
收藏
得分:0 
回复 3楼 sam_jiang
吹版说得对,调用 winAPI 函数实现窗体淡出效果,仅对顶层窗体有效,因为 winAPI 函数获取的 窗体句柄 实际是 VFP 窗体本身 _VFP 或 _Screen/_Command 等顶层窗体
2026-03-15 17:16
hsfisher
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:274
专家分:142
注 册:2009-4-26
收藏
得分:0 
2026-03-16 09:11
sam_jiang
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:14
帖 子:1141
专家分:1680
注 册:2021-10-13
收藏
得分:0 
回复 5楼 DANSON
回复 4楼 吹水佬

嗯,是顶层表单才可以淡入淡出,修改了一下代码,可以表现各种动画效果,就是不知道为什么动画过程中,表单的背景会变黑。

程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\animatewindow.scx)
*-- 父类:  form
*-- 基类:    form
*-- 时间戳:   03/21/26 03:09:03 PM
*
DEFINE CLASS form1 AS form


    ShowWindow = 2
    DoCreate = .T.
    AutoCenter = .T.
    Caption = "Form1"
    WindowType = 0
    Name = "Form1"


    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        Caption = "表单动画效果演示", ;
        Height = 16, ;
        Left = 24, ;
        Top = 12, ;
        Width = 98, ;
        Name = "Label1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 216, ;
        Left = 300, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "演示", ;
        Name = "Command1"


    ADD OBJECT combo1 AS combobox WITH ;
        Enabled = .F., ;
        Height = 24, ;
        Left = 24, ;
        Top = 60, ;
        Width = 156, ;
        Name = "Combo1"


    ADD OBJECT check1 AS checkbox WITH ;
        Top = 36, ;
        Left = 24, ;
        Height = 16, ;
        Width = 132, ;
        Alignment = 0, ;
        Caption = "淡入淡出", ;
        Value = 1, ;
        Name = "Check1"


    PROCEDURE Destroy
        DECLARE integer AnimateWindow in win32api integer hwindow,integer dwtime,integer dwflags
        animatewindow(this.HWnd,1000,0x10000+0x80000) &&淡入淡出效果
    ENDPROC


    PROCEDURE Load
        DECLARE integer AnimateWindow in win32api integer hwindow,integer dwtime,integer dwflags
        animatewindow(this.HWnd,1000,0x80000+0x20000)
    ENDPROC


    PROCEDURE command1.Click
        IF thisform.check1.Value=1
            naction=0x80000
        ENDIF 
        IF =.t.
            DO CASE 
                CASE =1
                    naction=0x01
                CASE =2
                    naction=0x02
                CASE =3
                    naction=0x04
                CASE =4
                    naction=0x08
                CASE =5
                    naction=0x10
            ENDCASE 
        ENDIF 

        animatewindow(thisform.HWnd,1000,naction+0x10000) &&滚动
        INKEY(1)
        animatewindow(thisform.HWnd,2000,naction+0x40000) &&滑动,注意观察他们的区别
        thisform.Hide()
        thisform.show()
    ENDPROC


    PROCEDURE combo1.Init
        this.AddItem("从左向右显示窗口") &&0x1
        this.AddItem("从右向左显示窗口") &&0x2
        this.AddItem("从上向下显示窗口") &&0x4
        this.AddItem("从下向上显示窗口") &&0x8
        this.AddItem("从中间开始缩放") &&0x10
        this.Value=5
    ENDPROC


    PROCEDURE check1.InteractiveChange
        IF this.Value=0
            =.t.
        ELSE 
            =.f.
        ENDIF 
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

2026-03-21 15:17
sam_jiang
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:14
帖 子:1141
专家分:1680
注 册:2021-10-13
收藏
得分:0 
这个animatewindow产生背景变黑的问题不知道怎么解决,deepseek给我另外方案,实现淡入淡出效果比较好,可以用作自己应用软件的封面以、版权申明什么的地方~
代码如下:
程序代码:
PUBLIC oform
oform=CREATEOBJECT("form1")
oform.show(1)
RETURN 

DEFINE CLASS form1 AS form
    ShowWindow = 2
    DoCreate = .T.
    AutoCenter = .T.
    *Caption = "Form1"
    WindowType = 0
    Name = "Form1"
    
    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        Caption = "无边框表单动画演示", ;
        FontSize = 12, ;
        ForeColor = RGB(0,0,255), ;
        Height = 20, ;
        Left = 24, ;
        Top = 20, ;
        Width = 150, ;
        Name = "Label1"

    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 80, ;
        Left = 24, ;
        Height = 32, ;
        Width = 100, ;
        Caption = "淡出淡入", ;
        Name = "Command1"
        
    ADD OBJECT command2 AS commandbutton WITH ;
        Top = 80, ;
        Left = 140, ;
        Height = 32, ;
        Width = 100, ;
        Caption = "关闭", ;
        Name = "Command2"

    PROCEDURE Init

        * 首先强制设置无边框无标题栏
        Thisform.TitleBar = 0
        Thisform.BorderStyle = 0
        
        * 声明 API 函数
        DECLARE INTEGER GetWindowLong IN user32;
            INTEGER hwnd, INTEGER nIndex
        DECLARE INTEGER SetWindowLong IN user32;
            INTEGER hwnd, INTEGER nIndex, INTEGER dwNewLong
        DECLARE INTEGER SetLayeredWindowAttributes IN user32;
            INTEGER hwnd, INTEGER crKey, INTEGER bAlpha, INTEGER dwFlags
            
        #DEFINE GWL_EXSTYLE -20
        #DEFINE WS_EX_LAYERED 0x80000
        #DEFINE LWA_ALPHA 0x2
        
        * 设置分层窗口属性(支持透明度)
        LOCAL lnStyle
        lnStyle = GetWindowLong(This.HWnd, GWL_EXSTYLE)
        lnStyle = BitOr(lnStyle, WS_EX_LAYERED)
        SetWindowLong(This.HWnd, GWL_EXSTYLE, lnStyle)
        
        * 初始完全可见
        = SetLayeredWindowAttributes(This.HWnd, 0, 255, LWA_ALPHA)
        
        * 设置表单背景色(防止黑背景)
        Thisform.BackColor = RGB(240, 240, 240)
    ENDPROC

    PROCEDURE FadeOut
        LPARAMETERS tnDuration
        DECLARE INTEGER SetLayeredWindowAttributes IN user32;
            INTEGER hwnd, INTEGER crKey, INTEGER bAlpha, INTEGER dwFlags
        #DEFINE LWA_ALPHA 0x2
        
        LOCAL lnAlpha, lnStep, lnDelay, lnStart
        lnStep = 255 / (tnDuration / 50)
        lnDelay = tnDuration / (255 / lnStep)
        
        * 淡出循环
        FOR lnAlpha = 255 TO 0 STEP -lnStep
            = SetLayeredWindowAttributes(Thisform.HWnd, 0, lnAlpha, LWA_ALPHA)
            Thisform.Refresh()
            = INKEY(lnDelay / 1000)
        ENDFOR
        
        * 确保完全透明
        = SetLayeredWindowAttributes(Thisform.HWnd, 0, 0, LWA_ALPHA)
        Thisform.Hide()
    ENDPROC

    PROCEDURE FadeIn
        LPARAMETERS tnDuration
        DECLARE INTEGER SetLayeredWindowAttributes IN user32;
            INTEGER hwnd, INTEGER crKey, INTEGER bAlpha, INTEGER dwFlags
        #DEFINE LWA_ALPHA 0x2
        
        LOCAL lnAlpha, lnStep, lnDelay
        lnStep = 255 / (tnDuration / 50)
        lnDelay = tnDuration / (255 / lnStep)
        
        * 显示表单
        Thisform.Show()
        
        * 淡入循环
        FOR lnAlpha = 0 TO 255 STEP lnStep
            = SetLayeredWindowAttributes(Thisform.HWnd, 0, lnAlpha, LWA_ALPHA)
            Thisform.Refresh()
            = INKEY(lnDelay / 1000)
        ENDFOR
        
        * 确保完全不透明
        = SetLayeredWindowAttributes(Thisform.HWnd, 0, 255, LWA_ALPHA)
    ENDPROC

    PROCEDURE command1.Click
        * 禁用按钮避免重复点击
        This.Enabled = .F.
        
        * 淡出
        Thisform.FadeOut(600)
        
        * 停顿一下
        = INKEY(0.2)
        
        * 淡入
        Thisform.FadeIn(600)
        
        * 恢复按钮
        This.Enabled = .T.
    ENDPROC
    
    PROCEDURE command2.Click
        * 带淡出效果的关闭
        Thisform.FadeOut(400)
        Thisform.Release()
    ENDPROC
    
    PROCEDURE Destroy
        * 清理 API 声明
        CLEAR DLLS
    ENDPROC

ENDDEFINE
2026-03-21 15:56
schtg
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:USA
等 级:贵宾
威 望:67
帖 子:2558
专家分:4954
注 册:2012-2-29
收藏
得分:0 
回复 8楼 sam_jiang
2026-03-21 19:57
快速回复:分享:一个完美实现窗体动态缩小最后完全消失的动画关闭效果的 UDF()
数据加载中...
 
   
关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025932 second(s), 10 queries.
Copyright©2004-2026, BCCN.NET, All Rights Reserved