Click here to Skip to main content
13,350,708 members (70,759 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 13 Jul 2009


, 13 Jul 2009
Rate this:
Please Sign up or sign in to vote.
A CStatic derived class that adds in fade in/out effect to your picture controls.


This MFC CStatic derived class will add in fade in/out effect to your picture control in your MFC project.


After writing the Cool FX wrapper, I thought I would write another simple MFC custom control using the same code structure, and here is the outcome.

Using the code

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

  1. Extract all the files from 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 CFadeStatic:
  3. #include "FadeStatic.h" 
  4. For the picture control in your resource editor window that you want to apply the fading effect, declare a control type variable for it using the Class Wizard and change the class from CStatic to CFadeStatic.
  5. You're done, build your application and see the Cool FX in action.

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

stcCodeprojectRuntime.Create(_T(""), WS_CHILD | WS_VISIBLE, ctrlRect, this);

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

All the fade in/out animation effect parameters can be set in the constructor of the CFadeStatic class. The "noisy" effect is just to add in some random dots during fade in/out.

Points of interest

The fading effect is done by creating two memory DCs: one for the background and one for the foreground bitmap. Then, the foreground bitmap DC is AlphaBlend() to the background DC; the resulting bitmap DC is then BitBlt() to the paint DC of the control.


  • 2009-07-14: Initial post.


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


About the Author

Hou Tianze
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralFade all other windows than mine Pin
TSchind20-Jul-09 22:38
memberTSchind20-Jul-09 22:38 

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.180111.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Hou Tianze
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid