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

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds