Transparent Animation Control
Environment: VC6 SP3, NT4 SP4 German (demo application tested with Win98 German)
As I wanted to put some animations (animated GIFs converted to AVIs)
in my application by using the standard CAnimateCtrl, I realized that Microsoft
and I interprete the term "transparent" differently.
If you set the flag ACS_TRANSPARENT in CAnimateCtrl, the background
of the animation is in no way transparent, instead it is changed to COLOR_WINDOW.
Not what I expected...
Since my application has a bitmap background the standard control was useless for me, and after staring some time at the AVIView sample sources, I decided to make my own class that supports real transparency ;-)
The following list shows the public functions of my class CAVICtrl and the flags you can use when loading an animation:
// functions
HRESULT Load(UINT nIDResource, DWORD dwFlags = 0L, COLORREF clrTransparent = LTGREEN); // load from resource HRESULT Load(LPCTSTR lpszFile, DWORD dwFlags = 0L, COLORREF clrTransparent = LTGREEN); // load from file BOOL Play(BOOL bOnce = FALSE); BOOL Stop(BOOL bResetToFirst = FALSE); void Seek(UINT nTo); BOOL IsPlaying(); // call this function if the background of the parent // window changesvoid ReinitBackground(); // flags to use with Load() AVC_HALFSPEED 0x0000001 // plays video with half speed AVC_DOUBLESPEED 0x0000002 // plays video with double speed AVC_CENTERAVI 0x0000004 // centers video inside the window AVC_STRETCHAVI 0x0000008 // stretches video to fit inside of the window AVC_CENTERRECT 0x0000010 // resizes window, center point stays the same AVC_AUTOPLAY 0x0000020 // starts playing automatically after Load() // background is COLOR_WINDOW // instead of transparent (like CAnimateCtrl's // AVS_"TRANSPARENT") AVC_MAPWINDOWCOLOR 0x0000040 // ignore clrTransparent parameter and uses color of first // frame's first pixel instead (works only with 8bit images) AVC_FIRSTPIXTRANSPRNT 0x0000080If you have a dialog based application, simply add a static control to your dialog and subclass it with a CAVICtrl in OnInitDialog() before calling one of the loading functions.
I recommend downloading the demo project which demonstrates the classes usage and the working of some of the flags.
This sample program also uses Joerg Koenigs very useful CBitmapDialog class to display the background image.
One great flaw is that the animation function itself is driven by a
timer, so it stops if you click on the parent window to move or resize
it.
I'm planning to put the animation code in a different thread for better
performance and appearance, but this will be my first travel into the alien
world of multithreaded programming, so please be patient ;-)
Comments, suggestions, bug reports etc. are welcome! Put them here as a comment or send them directly to me.
Enjoy!
Downloads
Download demo project - 140 KbDownload source - 6 Kb

Comments
I like it!
Posted by chi_luci on 03/07/2005 04:32pmvery nice job!
ReplyWhat about the status bar
Posted by andrew@appliedcytometry.com on 04/02/2004 05:23amI wish to use a small avi with transparent background in a status bar pane. Is it possible with this code?
ReplyWhat about w/o MFC?
Posted by Legacy on 11/05/2003 12:00amOriginally posted by: Chris Brown
How would you convert such a program to non-MFC code? would it be quite the project?
ReplyProblem with Seek() fixed
Posted by Legacy on 04/23/2003 12:00amOriginally posted by: BennyK
ReplyDoesn't run in a separate thread
Posted by Legacy on 01/27/2003 12:00amOriginally posted by: Marc
If I load an AVI inside a thread function AVIStreamOpenFromFile() fails... what should I do?
ReplyWhat about 24 bits AVIs???
Posted by Legacy on 01/24/2003 12:00amOriginally posted by: Marc
I am loading a 24 bits avi and no transparency... where should I modify it???
ReplyWriting Animation Control In Assembly
Posted by Legacy on 10/29/2002 12:00amOriginally posted by: Steve
Can a true transparent animation control be written in assembly such as MASM32. I'm not familiar with C++ etc.
Thanks in advance.
Congratulations to the person who wrote that transparent animation. I know it's not easy.
Replyfull-screen an AVI
Posted by Legacy on 06/24/2002 12:00amOriginally posted by: ran
How to enlarge the AVI movie or how to full-screen it???
ReplyDialog moving problem fixed !!!
Posted by Legacy on 04/30/2002 12:00amOriginally posted by: BlueDragon
ReplyFix : Strange Behavior when moving dialog !!!
Posted by Legacy on 07/04/2001 12:00amOriginally posted by: Binh Nguyen
ReplyLoading, Please Wait ...