Status Bar with AlphaBlend Fading Text

Introduction

Recently, I was enhancing the status bar in a project I was working on to support colors. This is easy enough to do and there are plenty of examples freely available. However, I wanted to take this a step further and put in support for AlphaBlending to allow the text in the status bar panes to fade in and out. The CCustomStatusBar class is the result.

What Is AlphaBlending?

AlphaBlending is a mechanism for blending a source graphic with a destination graphic. Each of the graphics is assigned a value that determines its translucency. The idea is to show both of the graphics at once one on top of the other but in a transparent state. By varying the translucency value for both graphics, it can appear that one of the graphics fades into the other one. Everybody has seen this effect. Watch nearly any movie and you'll come across a transition between two scenes that exhibit this effect.

How It Works

The class works by creating two drawing surfaces in memory, upon which it draws the pane of the status bar with the text set to be two different colors. It then AlphaBlends these two together in memory and passes the result back to the screen for display. To show a fading effect, it varies the translucency values every time a timer is fired. This gives the illusion of fading text.

Class Usage

The class is meant to be used as a drop in replacement for the standard CStatusBar class. The only caveat is that you need to make all the panes support owner draw for them to receive all the drawing notifications. Typically, this is done in the OnCreate of CMainFrame and this is how I did it in the example code.

The other minor issue is that you need to decide whether you want the class to manage the timer which in turn manages the fading or whether you want to use some other mechanism external to the class to manage the fading. If you want to keep it simple, have the class manage the timer by calling CCustomStatusBar::ManageTimer(true) in OnInitialUpdate of your frame or view.

If you prefer to call the fade function manually, simply call CCustomStatusBar::FadeStep() every time you want to change the translucency value. Why would you want to do this? Well, it does give you a bit more control over the rate of the fade. Or, possibly you want to tie the fade to some other routine in your application.

Example Code

The example code shows a simplistic implementation that demonstrates some of the class' functionality. Clicking on the view will cycle through several modes of fading that can be achieved with this class.



Downloads

Comments

  • Nicely done

    Posted by kirants on 11/13/2005 03:09pm

    Well written and useful class

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds