Click here to Skip to main content
Licence CPOL
First Posted 13 Jul 2009
Views 11,534
Downloads 503
Bookmarked 19 times

CFadeStatic

By Hou Tianze | 13 Jul 2009
A CStatic derived class that adds in fade in/out effect to your picture controls.

1

2
1 vote, 25.0%
3
2 votes, 50.0%
4
1 vote, 25.0%
5
3.83/5 - 4 votes
μ 3.83, σa 1.43 [?]

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 :); 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)

About the Author

Hou Tianze



Singapore Singapore

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralFade all other windows than mine PinmemberTSchind22:38 20 Jul '09  

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Hou Tianze
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid