Click here to Skip to main content
13,861,604 members
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 25 Mar 2001
Licenced CPOL


, 25 Mar 2001
Rate this:
Please Sign up or sign in to vote.
A Microsoft scandisk like control (in terms of its UI) that lets you put a series of blocks on screen.

Sample Image - CheckerCtrl.gif


I've been navigating the net for some days in order to find a control like Microsoft Scandisk's one (in terms of GUI not the behavior), but I didn't find any. So I created a class named CCheckerCtrl which does the same. You can fill a series of blocks with a color of your own choice, as well as get the color of any block.

How to use

To use the control, you import the header file as well as the .cpp file attached to this article. Then you simply open the dialog editor and place a rectangle on your dialog. We call this static control IDC_STATIC_CHECKER. Thereafter, you instantiate an object from CCheckerCtrl class, say m_ctrlChecker, as a public data member of your dialog class.

Then in the message handler of WM_INITDIALOG message you get the area  of the static rectangle you already placed on your dialog box and you simply create the checker control as follows:

//Declaring a local variable
CRect rect; 
//Get the rectangulare 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);

After doing so, the checker's window is shown on the screen. Now, we use SetTotalBlocks method of class to set the total number of blocks we would like the checker control to contain:

//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 index of the starting block. Lets say you need to number those blocks from 5 to 505. To do so, you give 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 the 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 the 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 example,

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 the class, Reset() which resets all the blocks' 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 the class at the creation time. You can define a handler for this message with the following prototype:

UINT OnRclickedChecker(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 controls on the same dialog box.

Final note

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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mehdi Mousavi
United States United States
Mehdi Mousavi is a professional computer programmer. He has written many programs using C, C++, MFC, Win32, COM, DCOM, JavaScript, ASP, HTML, DHTML, SQL, C# and MC++.

You may also be interested in...

Comments and Discussions

Generalyou should use cache to draw picture in OnPaint() [modified] Pin
andrew20030704@yahoo.com21-Mar-08 1:18
memberandrew20030704@yahoo.com21-Mar-08 1:18 
GeneralRe: you should use cache to draw picture in OnPaint() [modified] Pin
dchris_med26-Jun-13 5:06
memberdchris_med26-Jun-13 5:06 
Generalhelp Pin
hfeihuang27-Apr-03 20:01
memberhfeihuang27-Apr-03 20:01 
GeneralResize, No Flicker, ScrollBar drag enhancements. Pin
dchris_med26-Jun-13 5:14
memberdchris_med26-Jun-13 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190214.1 | Last Updated 26 Mar 2001
Article Copyright 2001 by Mehdi Mousavi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid