Click here to Skip to main content
12,754,090 members (30,136 online)
Click here to Skip to main content
Add your own
alternative version


56 bookmarked
Posted 29 May 2002


, 29 May 2002
Rate this:
Please Sign up or sign in to vote.
A class that creates special appearing and disappearing effects on CWnd objects or derivatives
Blinds (Horz)
Melt (Left)
Wipe (Vert)

The Pitch

Ever get bored minimizing, maximizing & restoring windows? Ever wanted to catch the user unawares and make them notice an app that's just that little bit special. Ever wanted to make a stealth program that literally slides into the background. Well with the CWindowAnima class you can now animate the appearance and disappearance of windows in ways a little different from the norm. There are twelve effects in total, six &"vanishing&" effects and six opposite &"appearing&" effects. They include Blind, Melt, Wipe, Scatter4, Scatter6, SlideVanish, UnBlind, UnMelt, UnWipe, ReAssemble4, ReAssemble6 and SlideAppear.

What's more these effects can be done on buttons, dialogs and anything else that's a CWnd derivative. The sample project (seen above) demonstrates all twelve effects on a simple dialog box. The project also includes an exploding button (using the Scatter6 effect) but I didn't include the screen shot, so I guess you'll have to download the project to see it! ;)

CWindowAnima works by capturing images of both the screen and the window and animating the image of the window. There are a comprehensive list of functions contained within the class and several flags and options that need explaining so nothing like a few examples to get us going.

The following code is pulled straight from the example project but I'll reproduce it here none the less. Further down this page you'll find a few notes, the parameters to the various effects (because where's the fun if you can't tweak it a little to suit your needs) and a summary of the public functions. If you manage to get past all of that you're rewarded with a link to the project files and source code.

Example #1 - Melting & UnMelting

// set the window for animation and specify that it should // not draw over the task bar
CWindowAnima wa(this, WA_KEEP_TASKBAR_ONTOP);

// melt the window to the left side of the screen,
// using 6 segments and stagger each segment 80 pixels
wa.Melt(WA_LEFT,6,80); // wait 3 secs Sleep(3000); // move the window to a new position

// Unmelt the window using the default (WA_AUTO) which unmelts
// the window from the side of the screen closest to the
// top-left corner of the window

Example #2 - SlideVanish & SlideAppear

// create the animation object but specify that 
// it should not draw over the task bar 
// slide the window out of view

// sleep for three seconds

// skip window capture and do not restore window nor image behind the
// window when a &"restoring&" animation is performed

// replace the window with the image whose resource ID is &"IDB_HOUSE&"

// slide our window into view, except now it's the image IDB_HOUSE.
// Also, don't restore the window until we're specifically told to.

// wait 2 secs

// called like this, Restores the window irrespective of the

Example #3 - Blind & UnBlind

// Create the object using the default constructor
CWindowAnima WA;

// sets the window for animation to be this dialog window

// Blind the window into invisibility using horizontal blinds

// Sleep for a second

// Blind the window into visibility using the default // vertical blinds wa.UnBlind();

Author's Notes

Just a few things to say about this class. First of all while it should (gotta cover myself for any eventualities) work on any CWnd derivative, it's probably best only to animate relatively small dialogs and buttons or at least give the user the opportunity of animating the window or not. Basically large windows will crawl sluggishly around your screen and the user will get bored and then annoyed.

Secondly if you find that the window sometimes gets smeared across the screen. I.e. the old image during an animation isn't overwritten look at the HideWindow() function as it may help.

Thirdly if anyone could provide some code to do some fast image rotation or even better a new effect or two, I'd appreciate it.

So that's pretty much it - enjoy!

Effects Function Parameters

Animation Effect
Function Parameters
Blind & UnBlind
Parameter Name
Default Value
Melt & UnMelt
Parameter Name
Default Value
Wipe & UnWipe
Parameter Name
Default Value

Scatter4 & ReAssemble4

Scatter6 & ReAssemble6

Parameter Name
Default Value
SlideVanish & SlideAppear
Parameter Name
Default Value

Summary of Public Functions

CWindowAnima()There are two constructors for CWindowAnima objects. The default constructor takes no arguments and any object created this way needs to call SetWindow() before any animations are done. The second constructor takes a pointer to a CWnd object or derivative as its first parameter and any flags as its second parameter. Internally the constructor calls FlagSet() and SetWindow() in that order.
FlagSet()Sets the flags member variable with the nFlags parameter. Returns the current state of the flags.
FlagUnset() Unsets the flags member variable with the nFlags parameter. Returns the current state of the flags

Returns either TRUE or FALSE depending on whether a flag or set of flags is set or not.

CopyWindowCapture() Grabs a copy of the window that another CWindowAnima object has gone to all the trouble of capturing. Also makes sure (in debug mode) that some idiot hasn't passed us a pointer to an CWindowAnima object that hasn't got a window image.
CopyScreenCapture() Grabs a copy of the screen that another CWindowAnima object has gone to all the trouble of capturing. Also makes sure (in debug mode) that some idiot hasn't passed us a pointer to an CWindowAnima object that hasn't got a screen image.

Replaces a window's image and size using an image resource ID. Useful if you wanted to animate the initial appearance of a window whose image has not been captured before. This function is overloaded and the user may also choose to replace a window's image and size with an image contained in a CDC object.

SetClippingRegion() Sets the clipping region rectangle for the animation and updates the screen dimensions. Takes a CRect object as an input parameter or four integers describing a bounding box.
GetClippingRegion()Returns the current Clipping Region and the classes' idea of how big the screen is. Clipping region and screen size are set to the same values internally.
SetWindow() Sets the window to be animated and captures an image of the window. Asserts (in debug mode) if the window given as a parameter is NULL.
GetWindow()Returns a pointer to the window that was stored when the object was initialised in the constructor or when the SetWindow function was called.
GetWindowRect() Copies the window's bounding rectangle into the empty CRect structure passed to it as a parameter.
MoveWindowPosition() Repositions the window being animated to the new coordinates specified by x and y integers and updates any internal variables that keep track of window position.
ShowWindow() Simply calls the CWnd function ShowWindow(SW_SHOW) on the internal window pointer.
RestoreWindow() Restores the window and the proper background of the window to their proper location. Internally RestoreWindow() is called with its parameter set to FALSE so it will check for the WA_KEEP_WINDOW_HIDDEN, WA_KEEP_BKGRND_HIDDEN or WA_WND_SKIPRESTORE flags (see the flags section for more information on what these flags do). Calling RestoreWindow() externally with no parameters causes the function to use the default value TRUE as its parameter and therefore ignore the value of any of the flags. It is assumed that the only reason a user would call this function explicitly is to restore a window irrespective of what the flags are set to.
Animation Functions
Blind()Creates a blinds disappearing effect on the window. There are two types of effect, vertical blinds or horizontal blinds. Use the WA_VERT or WA_HORZ direction values to choose the desired effect.

Creates a blinds appearing effect on the window. This is similar to the &"Blinding&" effect described above and the possible direction values are identical.

Wipe()Wipes the window into oblivion. The type of wipe animation depends on the direction value passed to it. Valid directions are WA_LEFT, WA_RIGHT, WA_UP, WA_DOWN, WA_HORZ, WA_VERT, WA_RAND(default), WA_AUTO.
UnWipe()UnWipes the window into existence. The type of Unwipe animation depends of the direction value given. Valid directions are the same as those in the &"Wiping&" animation above.
Melt()Melts the window off the screen. The direction the window will melt towards is dependent on the direction value given. Valid directions for this animation are WA_LEFT, WA_RIGHT, WA_UP, WA_DOWN, WA_RAND, WA_AUTO (default).
UnMelt()UnMelts the window onto the screen. The screen edge that the window will unmelt from is dependent on the direction value given. Valid directions are the same as those for the &"Melting&" animation above.
Scatter4() Splits the window into four separate rectangles and sends each part flying away from the window's center point
ReAssemble4() Four separate parts of a window fly from different directions to a central point where they join to make a full window.
Scatter6() Splits the window into six separate rectangles and sends each part flying away from the window's center point
ReAssemble6()Six separate parts of a window fly from different directions to a central point where they join to make a full window.
SlideVanish()Two partitions slide horizontally away from eachother underneath the window. The window then disappears into the black void, Finally the partitions close back together leaving the screen intact minus the window.
SlideAppear()Two partitions slide horizontally away from eachother opening into a black void. Zooming out of the void the window appears. The partitions then close slide back together again behind the now fully visible window.
WA_SCR_SKIPCAPTUREEach time a CWindowAnima object performs an animation it captures the area of the screen inside the clipping region. By setting this flag the animation will not capture the screen when it executes. You might use this if you've copied the screen image from another CWindowAnima object or else the window will disappear and appear in a very short space of time and the screen appearance is unlikely to change in the meantime.
WA_WND_SKIPCAPTUREWhen a CWindowAnima object is initialised it tries to capture an image of the window being animated. By setting this flag CWindowAnima will not capture the screen image. Important to set this flag if the window you're going to animate is invisible when you initialise the CWindowAnima object or when you're copying the image of the window between to objects.
WA_WND_SKIPRESTOREBy setting this flag the real window will not be restored to view after &"appearing&" effects such as UnBlind, UnMelt, SlideAppear, UnWipe, ReAssemble4 or ReAssemble6. This flag overrides both the WA_KEEP_WINDOW_HIDDEN & WA_KEEP_BKGRND_HIDDEN flags.

Normally when an &"appearing&" effect has finished executing the correct window background is printed onto the screen and the real window is then set to visible. By setting this flag the correct window background is painted to the screen but the window is not made visible. A call to either RestoreWindow or ShowWindow is needed.

WA_KEEP_BKGRND_HIDDENNormally when an &"appearing&" effect has finished executing the correct window background is printed onto the screen and the real window is then set to visible. By setting this flag the window is made visible but the window background is never painted to the screen. This usually results in having an image of the window stuck behind the real window instead of the correct background. A call to RestoreWindow is needed to correct the problem.

Setting this flag adjusts the clipping region to exclude the Windows Taskbar. When this flag is set animations will seem to appear from and disappear under the taskbar instead of the default which is to animate over the Windows Taskbar.

WA_SKIPHIDEONCAPTUREWhen an animation captures the screen, it calls the window's CWnd ShowWindow() function with the SW_HIDE parameter. Setting this flag ensures that the window is not hidden when a screen capture is performed.
WA_RANDIn the Melt, UnMelt, Wipe & UnWipe effects causes the animation to execute in a random direction.
WA_AUTOIn the Melt & UnMelt effects causes the window to melt towards or unmelt from the side of the screen closest to the window's top-left corner.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralNice effects, keep up the good work Pin
OrrW21-May-09 2:34
memberOrrW21-May-09 2:34 
GeneralRegion Problems Pin
Manoj Kumar Krishnamoorthy7-Dec-02 1:31
memberManoj Kumar Krishnamoorthy7-Dec-02 1:31 
GeneralXP problems Pin
S van Leent30-May-02 11:08
memberS van Leent30-May-02 11:08 
GeneralRe: XP problems Pin
Anonymous31-May-02 7:54
memberAnonymous31-May-02 7:54 
GeneralJust curious Pin
Smart Assed SOB30-May-02 6:58
memberSmart Assed SOB30-May-02 6:58 
In your demo the melt example shoots off to the left of the screen and then drops down from the top. Shouldn't return to the same location as it started? It ends up to the right and lower from where it started.

No problem, I was just curious...

Confused | :confused: Smart Assed SOBConfused | :confused:

GeneralRe: Just curious Pin
Anonymous31-May-02 7:52
memberAnonymous31-May-02 7:52 
GeneralThis stuff stinks Pin
kokie29-May-02 21:14
memberkokie29-May-02 21:14 
GeneralRe: This stuff stinks Pin
The Author31-May-02 8:02
memberThe Author31-May-02 8:02 
GeneralDownload links don't work Pin
Matt Philmon29-May-02 21:00
memberMatt Philmon29-May-02 21:00 
GeneralRe: Download links don't work Pin
Chris Maunder29-May-02 21:02
adminChris Maunder29-May-02 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 30 May 2002
Article Copyright 2002 by DigitalConvict
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid