主要是使窗口具有动态效果,通常是动态显示公司的商标或者公司的宣传材料。
函数声明(winuser.h)
#if(WINVER >= 0x0500)
WINUSERAPI
BOOL
WINAPI
AnimateWindow(
__in HWND hWnd, // 窗口的句柄
__in DWORD dwTime, // 动态出现的时间,单位:milliseconds
__in DWORD dwFlags); // 显示效果的标志设置
#endif /* WINVER >= 0x0500*/
参数
dwFlags:
AW_SLIDE | Uses slide animation. By default, roll animation is used. This flag is ignored when used with the AW_CENTER flag. |
AW_ACTIVATE | Activates the window. Do not use this flag 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 the AW_HIDE flag is used or expand outward if the AW_HIDE flag is not used. |
AW_HOR_POSITIVE | Animate the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with the AW_CENTER flag. |
AW_HOR_NEGATIVE | Animate the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with the AW_CENTER flag. |
AW_VER_POSITIVE | Animate the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with the AW_CENTER flag. |
AW_VER_NEGATIVE | Animate the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with the AW_CENTER flag. |
返回值
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
但是在使用的过程中通常会遇到编译出错的情况,如:AnimateWindow未声明等,原因是这个函数的声明中有#if(WINVER >= 0x0500),解决方法有很多种:
1、在StdAfx.h靠前的地方重新定义
加上#undef WINVER
#define WINVER 0x500
2、修改Winuser.h中的#if(WINVER >= 0x0500),改为#if(WINVER >= 0x0400)
关于WINVER
Windows 95 and Windows NT 4.0 WINVER=0x0400
Windows 98 and Windows NT 4.0 _WIN32_WINDOWS=0x0410 and WINVER=0x0400
Windows NT 4.0 _WIN32_WINNT=0x0400 and WINVER=0x0400
Windows 2000 _WIN32_WINNT=0x0500 and WINVER=0x0500
Windows Me _WIN32_WINDOWS=0x0490
Windows XP and Windows .NET Server _WIN32_WINNT=0x0501 and WINVER=0x0501
Internet Explorer 3.0, 3.01, 3.02 _WIN32_IE=0x0300
Internet Explorer 4.0 _WIN32_IE=0x0400
Internet Explorer 4.01 _WIN32_IE=0x0401
Internet Explorer 5.0, 5.0a, 5.0b _WIN32_IE=0x0500
Internet Explorer 5.01, 5.5 _WIN32_IE=0x0501
Internet Explorer 6.0 _WIN32_IE=0x0560 or _WIN32_IE=0x0600
注意:
使用AnimateWindow来进行淡出时,此时窗口收不到鼠标消息了,如果你有需求:在窗口淡出即将消失时,如果鼠标移上去,窗口恢复正常显示,并且不消失。使用AnimateWindow是没办法实现的,只能使用其它方法。
不过还是有一点没搞明白,Windows XP的WINVER=0x0501,为什么使用AnimateWindow的时候还要重新定义WINVER