Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Blinking Cells For Chris Maunder's Grid Control

13 May 2005 5  
Create blinking cells for Chris Maunder's grid control.

Introduction

I had cause to make use of Chris Maunder's outstanding grid control in a recent project, but it was missing some very necessary functionality - the ability to blink one or more cells. This article discusses how I added this capability. It boils down to a derived class that does the work, and a thread that provides the ticker to turn on/off a "blinking cell" (I don't really believe in WM_TIMER). I used the code from these two additional CP articles:

General

Since the grid control supports cell colors, all I had to do was come up with a way to make a cell look like it was blinking, and then come with a way to actually make it blink. To make it look like it was blinking, I came up with a class that contains the original colors of the specified cell, as well as the blink colors for the specified cell. How you determine these colors is completely up to you, and most likely it's going to be application-specific. For our application, we wanted the cell to blink with a red background and white text.

The CBlinkCell Class

This class is extremely simple having nothing more than variables that contain the cell's row, column, and original background and foreground colors.

The CBlinkCellList Class

This class is equally simplistic in its construction, and it merely contains a list of cells that are supposed to be blinking. If a CBlinkCell item is in this list, the CBlinkGridCtrl class will blink the cell (specified by the row/column data members) until it's removed from the list. This class allows you to add and remove/delete cells from the blink list.

The CBlinkGridCtrl Class

This class is derived from the original CGridCtrl class, and simply adds the new blinking functionality. This way, you can insert this class at the appropriate spot in your inheritance chain without losing any functionality that you added to the grid control (or your own derived classes).

Using the CBlinkGridCtrl Class

Simply derive your own grid control from CBlinkGridCtrl. After that, it's a simple matter of starting the blink thread (which you can do from within your derived grid control), and then writing code to turn blinking for the desired cell(s) on and off.

Notes

I put the resource ID for the grid control used in the sample app into the file Constants.h. This is also where the user defined message for the blink tick is found.

Credit Where Credit Is Due

Many thanks go out to Chris Maunder for writing the original CGridCtrl code. We're currently using that code in an application that tracks patients as they are serviced in a trauma center.

The thread class I'm using was originally written by Dominik Filipp. It's an old article (from 1999) here on CP, but it does the job quite nicely. I also make use of his thread class in many of my own applications.

Links to both of these articles are provided at the beginning of the article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here