9 out of 16 rated this helpful - Rate this topic

AnimateWindow function

Applies to: desktop apps only

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 WINAPI AnimateWindow(
  __in  HWND hwnd,
  __in  DWORD dwTime,
  __in  DWORD dwFlags
);

Parameters

hwnd [in]

Type: HWND

A handle to the window to animate. The calling thread must own this window.

dwTime [in]

Type: DWORD

The time it takes to play the animation, in milliseconds. Typically, an animation takes 200 milliseconds to play.

dwFlags [in]

Type: DWORD

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.

ValueMeaning
AW_ACTIVATE
0x00020000

Activates the window. Do not use this value with AW_HIDE.

AW_BLEND
0x00080000

Uses a fade effect. This flag can be used only if hwnd is a top-level window.

AW_CENTER
0x00000010

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_HIDE
0x00010000

Hides the window. By default, the window is shown.

AW_HOR_POSITIVE
0x00000001

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
0x00000002

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_SLIDE
0x00040000

Uses slide animation. By default, roll animation is used. This flag is ignored when used with AW_CENTER.

AW_VER_POSITIVE
0x00000004

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
0x00000008

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

Type:

Type: BOOL

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

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
ShowWindow
Conceptual
Windows
Other Resources
WM_PRINT
WM_PRINTCLIENT

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Aero theme
Note that this function does not work correctly on windows vista/7 with the aero theme enabled.
AW_BLEND and window alpha blending
AW_BLEND does not work on a window with alpha blending enabled (translucent). The window shows or hide without animation (although you need to wait for the time to elapse for the function to return). Once the function returns, alpha blending is disabled on the window and animation works normally on further calls to the function.
Synchronous
The AnimateWindow function is synchronous. For example, if you specify 5000 for dwTime, the function will not return for 5 seconds.
AW_BLEND and WS_EX_COMPOSITED
Windows XP SP2(not tested elsewhere): If the window you are attempting to use AnimateWindow on has the WS_EX_COMPOSITED extended style, using the AW_BLEND flag, will only show the window instead of fading the window in to visibility.