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

CFadeStatic

, 13 Jul 2009 CPOL
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.

Introduction

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

Background

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 FadeStatic_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 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 Smile | :) ; the following snippet from the demo code shows how:

stcCodeprojectRuntime.Create(_T(""), WS_CHILD | WS_VISIBLE, ctrlRect, this);
m_runtimeBmp.LoadBitmap(IDB_CODEPROJECT_HIGH_COLOR);
stcCodeprojectRuntime.SetBitmap(m_runtimeBmp);

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.

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)

Share

About the Author

Hou Tianze

Singapore Singapore
No Biography provided

Comments and Discussions

 
GeneralFade all other windows than mine PinmemberTSchind20-Jul-09 22:38 

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 | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Hou Tianze
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid