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

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds