Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC

CCoolFXStatic

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
13 Jul 2009CPOL3 min read 49.1K   2.4K   58   7
A CStatic derived class that wraps the cool FX effect by dswigger.

Image 1

Introduction

The code here is just a wrapper class for dswigger's Really cool visual FX, to make it easy to include these cool visual effects in your MFC projects. So the major credits go to dswigger (with the CFireRoutine memory leak fixed by Adam °Wimsatt). The class also uses Chris Maunder's CDIBSectionLite class.

Background

Several days ago, I came across this stunning visual effect written by dswigger, I was very impressed. But when I tried to integrate it to the "About" box of my own little proggie, I found it wasn't that easy - there are still a number of manual steps to perform to get the effect shown. This wasn't very convenient, and I felt this piece of code is just too cool to be non-reuse-friendly, and thus decided to write an MFC class wrapper for it, so that with one line of code change in your project, you can turn your static pictures into Cool FX pictures.

Using the code

To use the CCoolFXStatic class, you can follow these steps:

  1. Extract all the files from CoolFXStatic_src.zip and copy them to your MFC project directory, and add them to your project.
  2. Add in the following inclusion statement in the source file where you want to use CCoolFXStatic and/or CRandomFXStatic.
  3. C++
    #include "CoolFXStatic.h"
    #include "RandomFXStatic.h" // when you want to use CRandomFXStatic also.
  4. For the picture control in your resource editor window that you want to apply the Cool FX effect, declare a control type variable for it using the Class Wizard and change the class from CStatic to CCoolFXStatic or CRandomFXStatic. Which class to use depends on which type of animation you'd like to see: CCoolFXStatic shows water effect by default, but you can customize the animation and the parameters later (see below). CRandomFXStatic is the best fit if you just want to pick a random eye-catcher.
  5. You're done, build your application and see the Cool FX in action.

You can also create CCoolFXStatic during runtime (though I can't really think of a condition where you need to perform runtime creation :); the following snippet from the demo code shows how:

C++
m_stcCodeprojectRuntime.Create(_T(""), WS_CHILD | WS_VISIBLE, ctrlRect, this);
m_bmpCodeprojectRuntime.LoadBitmap(IDB_CODEPROJECT_HIGH_COLOR);
m_stcCodeprojectRuntime.SetBitmap(m_bmpCodeprojectRuntime);

All you have to do is create the control using the Create() function, then set the bitmap using the SetBitmap() function. The SetBitmap() function is overloaded in CCoolFXStatic and will perform the FX initialization.

You can customize the water animation in CCoolFXStatic by changing the following member variables:

C++
int mouseMoveBlobRadius;
int mouseMoveBlobHeight;
int mouseClickBlobRadius;
int mouseClickBlobHeight;
// The folloing parameter controls the number of "raindrops" (just some
// randomly generated blobs) of the water FX, the smaller it is 
// ("1" is the smallest possible value), the more "raindrops" are likely
// to be generated.
int intervalsPerRaindrop;

SetFireAlpha() and SetPlasmaAlpha() are used to change the fire and plasma FX transparency correspondingly.

CRandomFXStatic is a derived class of CCoolFXStatic, just to help you make up your mind on which animation to show off :)

Points of interest

It may be worth a little mentioning where the FX initialization is done for the picture control created in the resource editor. When I started coding, I used the Class Wizard to generate a control variable for the picture control in the resource editor, and changed the class from CStatic to CCoolFXStatic, and tried to find a place (Windows message, overriding the virtual method of CStatic) where the MFC framework will call me after it has loaded in the bitmap for the picture control. But several attempts failed - I just couldn't find the suitable place to do the FX initialization. Then, I did some more trial-and-error and found a place where the MFC framework will call the PreSubclassWindow() virtual method of CWnd. Further tracing revealed why this place works for the Class Wizard generated dialog control variables: for every control variable generated using Class Wizard, a DDX_Control() function call will be added, and this function will call the SubclassWindow() method of the control variable, which in turns calls the PreSubclassWindow() method.

History

  • 2009-07-14: Initial post.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCenterize the bitmap image Pin
Patrick Shi10-Aug-11 8:01
Patrick Shi10-Aug-11 8:01 
AnswerRe: Centerize the bitmap image Pin
Hou Tianze24-Aug-11 22:55
Hou Tianze24-Aug-11 22:55 
GeneralYou do a great job Pin
zhourenyun21-Oct-10 16:30
zhourenyun21-Oct-10 16:30 
Generalw a good thing Pin
batsword20-Aug-10 18:51
batsword20-Aug-10 18:51 
GeneralVery good Pin
xwdd12916-Dec-09 18:55
xwdd12916-Dec-09 18:55 
Good job,thank you
JokeGood Job!! Pin
dnybz28-Aug-09 8:50
dnybz28-Aug-09 8:50 
GeneralVery cool and glad to see someone else was able to expand on it Pin
dekaya19-Aug-09 17:51
dekaya19-Aug-09 17:51 

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.