【Demo 0049】动画窗体

动画窗体主要指的是创建或显示时以及隐藏窗体陪随的动画显示或隐藏效果; Window 提供了一个叫AnimateWindow这样的API, 这个效果就是使用这个函数实现的.

1.  函数声明

     BOOL AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags);

     hWnd:         需动画效果的窗体句柄(此窗体要同属于动画效果线程的)

     dwTime:      动画的时间周期

     dwFlags:     动画效果类型

         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.

2.  代码演示

     1. 创建一个隐藏的窗体;

     2. 调用_DemoAnimateWnd函数,演示各种动画类型效果,演示过程: 动画显示并维持1秒后动画隐藏,不同类型效果切换间隔2秒


void _DemoAnimateWnd ( HWND hWnd )
{
     UINT dwEffType [] = { AW_BLEND , AW_CENTER , AW_HOR_POSITIVE ,
                          AW_HOR_NEGATIVE , AW_VER_POSITIVE , AW_VER_NEGATIVE };
     assert ( NULL != hWnd && IsWindow ( hWnd ));
     for ( int nIndex = 0; nIndex < ( sizeof ( dwEffType ) / sizeof (* dwEffType )); nIndex ++)
    {
         AnimateWindow ( hWnd , 300, dwEffType [ nIndex ]);
         Sleep (1000);
         AnimateWindow ( hWnd , 300, dwEffType [ nIndex ]| AW_HIDE );

         Sleep (2000);
    }

     return ;
}

 

演示代码

你可能感兴趣的:(demo)