Checker Control

Environment: VC++6.0, Windows 98, Windows NT

I needed the same UI functionality found in Microsoft Scandisk application. However, after looking around on the Internet for some time I was not able to find one. Therefore, I decided to create my own (called CCheckerCtrl). With this control (pictured above), you can fill a series of blocks with a color of your own choice, as well as retrieving the color of any block.

To use the control, do the following:
  1. Import the header file (including in the attached source code)
  2. Add the .cpp file (also attached to this article)
  3. Open the dialog editor and place a rectangle on the desired dialog. This control must have an id of IDC_STATIC_CHECKER.
  4. Define a member variable for the dialog of type CCheckerCtrl class. This variable can have whatever name you wish.
  5. In the dialog's OnInitDialog member function, insert the following code
    //Declaring a local variable
    CRect rect;
    //Get the rectangle coordinates of the 
    //rectangle we already placed on dialog
    //Convert to the client coordinates 
    //Create and place the checker control on screen
    m_ctrlChecker.Create(WS_VISIBLE | WS_CHILD 
                         | WS_VSCROLL | WS_TABSTOP, 
                         rect, this, IDC_STATIC_CHECKER);
  6. Now, we user SetTotalBlocks method of CCheckerCtrl class to set the total number of blocks we would like the checker control contains.
    //Creating and placing 500 blocks on the checker control
    The function is declared as follows:
    void CCheckerCtrl::SetTotalBlocks(const UINT nNumberofBlocks, 
                                      const UINT nStartIndex = 0);
    where nNumberofBlocks is the number of blocks we would like to place in checker control and nStartIndex is the starting index of blocks. i.e. sometimes you need to number those blocks from 5 to 505. To do so, you give the 5 as the nStartIndex. This way the first number of the first block will be 5, the second one 6, and so on... until 505. The default value is 0.

If you run the program now, you are faced with 500 white blocks. Now, you can simply set the color of a block by the following member function of class:

void CCheckerCtrl::SetBlock(const UINT nBlockNumber, 
                            const COLORREF crColor)
For example, to paint the 2nd, 3rd, 4th and 5th block of the control red, we will do the following:
for(register i = 2; i < 6; i++)
 m_ctrlChecker.SetBlock(i, RGB(255, 0, 0));

Now in order to make the changes to be refreshed, we simply call Refresh function of the class:


But sometimes you need an instant refresh of a block, so you can use Update method of the class. The declaration is as follows:

void CCheckerCtrl::Update(const UINT nBlockNumber);
for (register i = 2; i < 6; i++)
 m_ctrlChecker.SetBlock(i, RGB(255, 0, 0));

The next function of this control comes to play when we need to get the color of a specific block. To do so, GetBlock member function is used:

COLORREF GetBlock(const UINT nBlockNumber) const;

For example to get the color of the 6th block, we do this:

COLORREF crColor = m_ctrlChecker.GetBlock(6);
Finally, we come to the last member function of class, Reset() which resets all the block's color into white, again.

There's also a pre-defined message in this class, named WM_CHECKERCTRL_RBUTTONDOWN which is used when you need to control left-clicking, say, bring a popup menu on screen. Please note that the message will be send to the parent window which was given to class at creation time. You can define a handler for this message with the following prototype:

OnRclickedCherk(WPARAM wParam, LPARAM lParam)

where wParam is the control ID of checker control and lParam is the number of block the user is clicked on. Control ID is used to distinguish between different checker control on the same dialog box.

Since the source code is pretty straight forward, and fulfilled with Preconditions, Postconditions & different lines of comments, I think that this article is finished now. You can reach the author via his email address. Any comments, questions or suggestions are welcome. Aloha!


Download source - 4 Kb
Download demo project - 23 Kb


  • Don't work ScrollBox Event.

    Posted by Legacy on 03/29/2001 12:00am

    Originally posted by: t.san

    hi. it's nice class.

    However, the action of the scroll is imperfect.
    The scroll bar that belongs to this window seems
    to not able to process the event of the scroll
    box skillful

    Teach who or solution, to me

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

Top White Papers and Webcasts

  • Data integrity and ultra-high performance dictate the success and growth of many companies. One of these companies is BridgePay Network Solutions, a recently launched and rapidly growing financial services organization that allows merchants around the world to process millions of daily credit card transactions. Due to the nature of their business, their IT team needed to strike the perfect balance between meeting regulatory-mandated data security measures with the lowest possible levels of latency and …

  • The 3rd Platform of computing, based around the four pillars of mobile computing, social media, big data and analytics, and cloud, is redefining what IT infrastructure needs to provide. Endpoint solutions must meet not only traditional data protection requirements, but also a new set of requirements driven by the explosion in mobile computing. This IDC white paper explores the customer challenges associated with safeguarding data residing on various endpoint devices, including laptops, tablets, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date