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

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Event Date: April 15, 2014 The ability to effectively set sales goals, assign quotas and territories, bring new people on board and quickly make adjustments to the sales force is often crucial to success--and to the field experience! But for sales operations leaders, managing the administrative processes, systems, data and various departments to get it all right can often be difficult, inefficient and manually intensive. Register for this webinar and learn how you can: Align sales goals, quotas and …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds