Shape-Changing Progress Control

CSuperProgressCtrl Sample


     SP_FILL_VERTGRAD                  SP_FILL_VERT
CSuperProgressCtrl Fill Styles
     SP_FILL_HORZGRAD                  SP_FILL_HORZ

Environment: Windows 95, Visual C++ 4

While browsing through the CodeGuru site, I came across a number of articles on progress controls that do gradient shading and even bitmap shading, similar to Microsoft Combat Flight Simulator. I have not come across one piece of code, however, that allows a program to change the shape of a progress control. This progress indicator can be shaded in one of four different ways: solid horizontally, solid vertically, gradient horizontally and gradient vertically. All four are shown above, with the appropriate #define'd value to pass to SetFillStyle(). The colours used for shading are fully customizable, as is the background colour. The default background colour is the background colour of a dialog box, so it can be used in a dialog box with minimum overhead. The most interesting feature, however, is the ability to form the progress control into any shape, given by a bitmap.

The shape is passed to the Create() member function in the hbmArea parameter. This can be a colour or monochrome bitmap. Any colour that is non-white is used to form the progress control. Pixels that are white are transparent areas, and are not shaded. The bitmap is converted to a region, using a function from an article by Jean-Edouard Lachand-Robert. This region is then expanded by one pixel in both the horizontal and vertical directions. For this reason, make sure that the bitmap has a 2 pixel (at least) white border around any non-white pixels. This region is passed to the SetWindowRgn() function. The advantage of this is that we don't have to perform much clipping, and any windows underneath that are under the transparent areas can still be seen. The Create() function uses the width and height of the bitmap as the width and height of the progress control, so make your bitmap the same size as you would like the progress control to be.

Except for the Create() function. The progress control is designed to operate exactly as the CProgressCtrl MFC class, with a few additions. These additions are for setting the fill style and colours. I added a function that implements a MFC-compatible message loop. This function can be called regularly during a long operation, so that your program does not appear to have crashed. If a WM_QUIT message is received during this message loop, the function returns FALSE so that you can exit your processing loop, otherwise it returns TRUE.

NOTE: Before using this class, make sure you call the RegisterClass() function, to register the window class used by this control. This is a static member, so it can be called in CYourApp::InitInstance() (for example)

Please consult the source code and demo project for more information on this class.

Downloads

Download demo project - 30 Kb
Download source - 8 Kb


Comments

  • How to show the background out of the text?

    Posted by LeonOrient on 07/20/2005 05:57am

    It is great! Only it can not show the image outside of the text in the control region. Like to modify the onpaint function as below: 1.BitBlt-copy the image under the control field, how to do it? 2.Integrate it in the memory dc 3.Show it on screen But I failed... Can you help me?

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

Top White Papers and Webcasts

  • Available On-Demand Today's changing workforce dynamics, economic challenges, and technological advances are placing immense pressure on business leaders to turn their focus on people – their most valuable asset – in order to remain competitive. Research shows that a significant number of new employees quit within one year of taking a new job*. Whether it's through a merger and acquisition, or standard hiring process, like any first impression, early experiences shape their opinions of their new …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds