| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4204 人关注过本帖
标题:c#窗体动画效果.AnimateWindow()函数利用
只看楼主 加入收藏
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
 问题点数:0 回复次数:7 
c#窗体动画效果.AnimateWindow()函数利用

可以制作多种窗体的特效!!
我查到的资料,不巧是english的,我也不很理解,请高手翻译一下大家学习一下!!!



AnimateWindow Function


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

Syntax

BOOL AnimateWindow(

HWND hwnd,

DWORD dwTime,

DWORD dwFlags

);

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. Note that, by default, these flags take effect when showing a window. To take effect when hiding a window, use AW_HIDE and a logical OR operator with the appropriate flags.

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. The various direction flags have no effect.

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 Value

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:

If the window uses the window region. Windows XP: This does not cause the function to fail.

If the window is already visible and you are trying to show the window.

If the window is already hidden and you are trying to hide the window.

If there is no direction specified for the slide or roll animation.

When trying to animate a child window with AW_BLEND.

If the thread does not own the window. Note that, in this case, AnimateWindow fails but GetLastError returns ERROR_SUCCESS.

To get extended error information, call the GetLastError function.

Remarks

To show or hide a window without special effects, use ShowWindow.

When using slide or roll animation, you must specify the direction. It can be either AW_HOR_POSITIVE, AW_HOR_NEGATIVE, AW_VER_POSITIVE, or AW_VER_NEGATIVE.

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 should 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.

If a child window is displayed partially clipped, when it is animated it will have holes where it is clipped.

AnimateWindow supports RTL windows.

Avoid animating a window that has a drop shadow because it produces visually distracting, jerky animations.

Function Information

Header

Declared in Winuser.h, include Windows.h

Import library

User32.lib

Minimum operating systems

Windows 98, Windows 2000

See Also

Windows Overview, ShowWindow, WM_PRINT, WM_PRINTCLIENT



© 2003 Microsoft Corporation. All rights reserved.

搜索更多相关主题的帖子: 窗体 动画 函数 FONT 效果 
2006-04-15 14:45
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
在现有c#基础上,找不到AnimateWindow函数.

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-15 15:09
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 

MSDN可以找到呀,
我英语不好,不理解具体的用法!!!
能不能翻译一下!!!


锻炼中学习……学习中成长……
2006-04-15 15:52
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
BOOL AnimateWindow(
HWND hwnd,
DWORD dwTime,
DWORD dwFlags
);

  hWnd:指定产生动画窗口的句柄;
  dwTime:指明动画持续的时间(以微秒计),完成一个动画的标准时间为200微秒;
  dwFags:指定动画类型。这个参数可以是一个或多个标志的组合。

dwFlags:

  AW_SLIDE:使用滑动类型。缺省为滚动类型。使用AW_CENTER标志时被忽略;

  AW_ACTIVATE:激活窗口。在使用了AW_HIDE标志后不能使用这个标志;

  AW_BLEND:实现淡出效果。只有当hWnd为顶层窗口的时候才可以使用此标志;

  AW_HIDE:隐藏窗口,缺省则显示窗口;

  AW_CENTER:若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;若未使用AW_HIDE标志,则使窗口向外扩展,即展开窗口;

  AW_HOR_POSITIVE:自左向右显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略;

  AW_VER_POSITIVE:自顶向下显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略;

  AW_VER_NEGATIVE:自下向上显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略;

  返回值:如果函数成功,返回值为非零;如果函数失败,返回值为零。

如果:
1、窗口使用了窗口边界;
2、窗口已经可见仍要显示窗口;
3、窗口已经隐藏仍要隐藏窗口。
函数将失败。

在STDAFX.H中加入
#undef WINVER
#define WINVER 0X500

否则可能会产生如下错误(由于Windows版本问题):
 'AnimateWindow' : undeclared identifier
  'AW_HIDE' : undeclared identifier
  'AW_CENTER' : undeclared identifier

一个例子:

void CAboutDlg::OnClose()
{
//实现淡出效果。

AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);

CDialog::OnClose();

}


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-15 19:03
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 

摘要:本文通过对AnimateWindow函数的分析,介绍动画窗口的实现原理,同时指出了在运用AnimateWindow函数时在编译中会遇到的一些问题以及处理方法。

关键词:动画窗口,AnimateWindow,MSDN

动画窗口的实现

一、引言

俗话说"佛靠金装,人靠衣装",一个好的软件如果能配上精美的界面一定会让更多的用户认同它。喜欢上网的朋友对NetAnt(网络蚂蚁)这个软件一定不会陌生,它的下载速度,断点续传的功能都给我们留下了深刻的印象,同时它的软件界面也是相当棒的。在NetAnt的1.23版中,当下载任务完成或出错时,在主窗口的中央会以动画的方式展开一个窗口,报告当前下载的状况;当用户关闭窗口时,窗口又以收缩的方式关闭起来。那么这个动画窗口是怎样实现的呢?下面我们就来讨论一下在VC中如何实现这种动画窗口。

二、编程原理

要实现这种动画窗口的编程效果,主要用到Windows API中的AnimateWindow函数,通过在窗口的创建或消毁过程中运用该函数,来实现开启和关闭程序时达到所希望的动画窗口效果。AnimateWindow函数所提供的动画效果十分丰富,我们可以在自己的程序中选择各种不同的动画效果,增强程序的趣味性。为使读者对AnimateWindow函数有一个基本了解,我们先对该函数做一个简单介绍:

函数原型:BOOL AnimateWindow(HWND hWnd,DWORD dwTime,DWORD dwFlags)。

函数功能:该函数能在显示与隐藏窗口时产生两种特殊类型的动画效果:滚动动画和滑动动画。

参数含义:

hWnd:指定产生动画的窗口的句柄。

dwTime:指明动画持续的时间(以微秒计),完成一个动画的标准时间为200微秒。

dwFags:指定动画类型。这个参数可以是一个或多个下列标志的组合。标志描述:

AW_SLIDE:使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略。

AW_ACTIVATE:激活窗口。在使用了AW_HIDE标志后不能使用这个标志。

AW_BLEND:实现淡出效果。只有当hWnd为顶层窗口的时候才可以使用此标志。

AW_HIDE:隐藏窗口,缺省则显示窗口。

AW_CENTER:若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;若未使用AW_HIDE标志,则使窗口向外扩展,即展开窗口。

AW_HOR_POSITIVE:自左向右显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。

AW_VER_POSITIVE:自顶向下显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。

AW_VER_NEGATIVE:自下向上显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。

返回值:如果函数成功,返回值为非零;如果函数失败,返回值为零。在下列情况下函数将失败:

窗口使用了窗口边界;窗口已经可见仍要显示窗口;窗口已经隐藏仍要隐藏窗口。

三、动画窗口的实现

下面就以一个简单的单文档程序为例,说明如何在VC中使用AnimateWindow函数来实现打开和关闭程序时的动画效果。基于多文档与对话框的程序所用方法类似,本文就不一一介绍。笔者所使用的开发环境为:WindowsME,Visual C++6。

1、建立一个MFC AppWizard(exe)应用工程Animate。

在MFC AppWizard向导的第一步中选择Single document,再点击按键Finish->OK完成工程建立。

2、在CMainFrame::OnCreate函数中增加黑体加粗部分语句。

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ ……
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
AnimateWindow(GetSafeHwnd(),1000,AW_CENTER);
return 0;
}

3、使用MFC ClassWizard增加消息处理函数

使用ClassWizard在CMainFrame类中增加WM_CLOSE消息处理函数,并增加以下语句。

void CMainFrame::OnClose()
{// TODO: Add your message handler code here and/or call default
AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
CFrameWnd::OnClose();
}

四、编译时出现的问题

在实现动画窗口的程序时,笔者发现如果直接在VC中使用AnimateWindow函数,在编译时会报告出错。以上述程序为例,在编译时系统会报告:

'AnimateWindow' : undeclared identifier

'AW_HIDE' : undeclared identifier

'AW_CENTER' : undeclared identifier

通过错误提示可以看出是编译系统认为AnimateWindow函数和AW_HIDE、AW_CENTER两个参数没有定义。因该函数是定义在Winuser.h头文件中的,于时,笔者显示地在程序中定义了对该头文件的包含,编译时却仍然出现相同的错误。为什么在VC中编译不能通过呢?通过查阅MSDN笔者发现在MSDN中明确提到WindowsNT5.0和Windows98以上版本均支持该函数。通过笔者的研究发现,问题出在定义AnimateWindow函数的头文件Winuser.h中,在VC安装目录下进入include子目录,用EDIT打开Winuser.h文件,按F3键查找AnimateWindow,可以发现有两处定义,一处是定义该函数中使用到的参数;另一处是该函数原型的定义。在这两处定义中均出现了对Windows版本的条件判断,#if (WINVER >= 0X500)……,原来问题出在这里,我们目前所使用的各种Windows主版本号均为5点零以下,所以在VC中编译上述程序时,编译系统自然将AnimateWindow函数排除在外。因此为了在我们的程序中使用该函数,就得对其头文件进行一些小小的修改,即将#if (WINVER >= 0X500)改为#if (WINVER >= 0X400),请注意两处出现该函数定义的部分都要进行修改。

修改好头文件后,编译即可通过。

五、小结

实际上在AnimateWindow函数中包含了多种动画效果,我们只须在程序中增加几条语句,就能使得程序的开启和关闭就得生动有趣。

另外,通过本例我们可以发现,尽管在MSDN中明确指出在Windows98中支持AnimateWindow函数,但是在实际编程时却发现该函数在头文件中的定义却将版本控制在了5.0以上,笔者虽然不知道原因何在,但本文对此问题的解决无疑是一种比较新颖的作法,希望能够对广大读者的工作起到抛砖引玉的效果。


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-15 19:04
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
关于AnimateWindow的补充说明

前段时间经常在论坛或者文档上面讨论AnimateWindow的使用,或者有说到98下面不能使用的,或者有人说MSDN上面说98下一定能用的,我试了一下,2000下面我尚不能直接使用这个函数,98下面更不能够了。察看了一下User32.dll,那个函数又确确实实的存在,究其原因,就是用为这个函数的Winver定义在大于0x0500,这个问题已经有人在文章中提到了,他使用的是修改函数定义,将Winver降级使用,这种方法因为涉及到修改头文件,麻烦,而且心里面感觉怪怪的,因此就直接将AnimateWindow的使用方法修改成以下所列的:

首先定义常量:

#define AW_HOR_POSITIVE 0x00000001
#define AW_HOR_NEGATIVE 0x00000002
#define AW_VER_POSITIVE 0x00000004
#define AW_VER_NEGATIVE 0x00000008
#define AW_CENTER 0x00000010
#define AW_HIDE 0x00010000
#define AW_ACTIVATE 0x00020000
#define AW_SLIDE 0x00040000
#define AW_BLEND 0x00080000

相应的含义我相信MSDN大家都可以查找到的

实现部分如下:

typedef UINT (CALLBACK* LPFNDLLFUNC1)( HWND hwnd, DWORD dwTime, DWORD dwFlags);//定义AnimateWindow的函数指针

HINSTANCE h;
LPFNDLLFUNC1 p;
::ShowWindow(hWnd,SW_HIDE);
h = LoadLibrary( "user32.dll" );
p = (LPFNDLLFUNC1) GetProcAddress( h, "AnimateWindow" );
p(hWnd, 500,AW_HOR_POSITIVE|AW_SLIDE);
::ShowWindow(hWnd,SW_SHOW);
FreeLibrary( h );]

这段代码实现了一种从左向右的效果。

另外:

其实有许多函数都可以通过这种方式实现的,而不需要修改头文件定义。


我想用AnimateWindow 实现窗体的动态显示,编译时发现AnimateWindow 未定义,按msdn中的说法加入#include<winuser.h>#include<windows.h>还是不行,最后我用动态加载user32.dll的方法实现了AnimateWindow ,但参数AW_CENTER等仍通不过编译,我用0,1等数字代替,哪位高手知道AW_CENTER的定义在什么头文件中,或不用动态加载user32.dll如何实现

搜索头文件中包含AnimateWindow的头文件,把AnimateWindow的定义复制到您的函数定义文件就可以了.这是因为Microsoft使用一个宏定义,好奇怪的,MSDN中说明可以用的,有很多都被宏定义的版本太高而用不了,不过把它复制过来后就可以用了.

AnimateWindow 是为 Windows 2000 及更高版本操作系统设计的。
如果你用的是 Visual Studio 6.0, 就按楼上说的作;
如果你用的是 Visual Studio .NET, 就在 stdafx.h 中, 把所有 Windows 的版本号全改为 2000 的

#ifndef WINVER
#define WINVER 0x0500
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif

//#ifndef _WIN32_WINDOWS
//#define _WIN32_WINDOWS 0x0410
//#endif

//#ifndef _WIN32_IE
//#define _WIN32_IE 0x0400
//#endif


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-15 19:05
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 
非常感谢!!

锻炼中学习……学习中成长……
2006-04-16 20:06
ShaoLong888
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-5-5
收藏
得分:0 
在c#中怎么实现呀
2011-10-19 19:35
快速回复:c#窗体动画效果.AnimateWindow()函数利用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

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