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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds