Click here to Skip to main content
Click here to Skip to main content

WindowAnima

, 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)
Scatter4
SlideVanish
Scatter6

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! Wink | ;)

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
wa.MoveWindowPosition(600,400);

// 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
wa.UnMelt();

Example #2 - SlideVanish & SlideAppear

// create the animation object but specify that 
// it should not draw over the task bar 
CWindowAnima WA(this,WA_KEEP_TASKBAR_ONTOP); 
   
// slide the window out of view
wa.SlideVanish();

// sleep for three seconds
Sleep(3000);

// skip window capture and do not restore window nor image behind the
// window when a &"restoring&" animation is performed
wa.FlagSet(WA_WND_SKIPCAPTURE|WA_WND_SKIPRESTORE);

// replace the window with the image whose resource ID is &"IDB_HOUSE&"
wa.ReplaceWindowImage(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.
wa.SlideAppear();

// wait 2 secs
Sleep(2000);

// called like this, Restores the window irrespective of the
// WA_WND_SKIPRESTORE flag.
wa.RestoreWindow();

Example #3 - Blind & UnBlind

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

// sets the window for animation to be this dialog window
wa.SetWindow(this);

// Blind the window into invisibility using horizontal blinds
wa.Blind(WA_HORZ);

// Sleep for a second
Sleep(1000);

// 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
nDirection
WA_VERT
nSegments
8
nGapFactor
4
nSleeptime
100
Melt & UnMelt
Parameter Name
Default Value
nDirection
WA_AUTO
nSegments
6
nStagger
40
nSleeptime
1
Wipe & UnWipe
Parameter Name
Default Value
nDirection
WA_RAND
nWipeFactor
4
nSleeptime
20

Scatter4 & ReAssemble4

Scatter6 & ReAssemble6

Parameter Name
Default Value
nDistance
90
nMoveFactor
4
nSleeptime
1
SlideVanish & SlideAppear
Parameter Name
Default Value
nSlideFactor
1
nScaleFactor
15
nSlideDelay
10
nVanishDelay
0

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
FlagIsSet()

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.
ReplaceWindowImage()

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.
UnBlind()

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.
Flags
WA_SCR_SKIPCAPTURE Each 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_SKIPCAPTURE When 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_SKIPRESTORE By 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.
WA_KEEP_WINDOW_HIDDEN

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

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_SKIPHIDEONCAPTURE When 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.
Directions
WA_LEFT
WA_RIGHT
WA_UP
WA_DOWN
WA_VERT
WA_HORZ
WA_RAND In the Melt, UnMelt, Wipe & UnWipe effects causes the animation to execute in a random direction.
WA_AUTO In 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.

License

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

Share

About the Author

DigitalConvict

United States United States
No Biography provided

Comments and Discussions

 
GeneralNice effects, keep up the good work PinmemberOrrW21-May-09 1:34 
Smile | :)
GeneralRegion Problems PinmemberManoj Kumar Krishnamoorthy7-Dec-02 0:31 
GeneralXP problems PinmemberS van Leent30-May-02 10:08 
GeneralRe: XP problems PinmemberAnonymous31-May-02 6:54 
GeneralJust curious PinmemberSmart Assed SOB30-May-02 5:58 
GeneralRe: Just curious PinmemberAnonymous31-May-02 6:52 
GeneralThis stuff stinks Pinmemberkokie29-May-02 20:14 
GeneralRe: This stuff stinks PinmemberThe Author31-May-02 7:02 
GeneralDownload links don't work PinmemberMatt Philmon29-May-02 20:00 
GeneralRe: Download links don't work PinadminChris Maunder29-May-02 20:02 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 30 May 2002
Article Copyright 2002 by DigitalConvict
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid