Click here to Skip to main content
13,355,726 members (84,415 online)
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 24 Nov 2002

A Generic Well Control (ColorPicker, ArrowPicker and more)

, 24 Nov 2002
Rate this:
Please Sign up or sign in to vote.
Provides and demonstrates the use of a generic "well" control that can be used to facilitate color-pickers, hash-style selectors amongst others

Sample Image - maximum width is 600 pixels Sample Image Sample Image - maximum width is 600 pixels Sample Image - maximum width is 600 pixels


I need a color picker for a vector drawing program I am developing. After trying several color picker examples from CodeGuru and CodeProject, I found what I really need is a general 'well' control. It can not only serve as the base class of color picker, but also others. Also, I want this well control can be used as button in a dialog or from view, as well as a popup window. I also think it is good to use bitmap resource to draw each well if owner draw is not necessary.

Using the code

Copy all the *.h file and *.cpp to your project. If you want to use the Office-style color picker, please add the resource for the dialogs and bitmaps to your project also. There are four well controls in the demo project:

, CSVizArrowWell, CSVizLineStyleWell, CSVizHatchWell. Because the color well is not only choosing color but also the pattern of filling (GD+ HatchBrush), you need to download Microsoft SDK for the GDI+ support. These four well controls are derived from
If you want to implement your own well control, you can derived your CXXXWell from CSVizWellCtrl. In most of cases, you only need to override the following three virtual functions and constructor:

virtual void Initialise ();
virtual CString GetWellName (int nIndex) { return "well"; }
virtual void DrawCellContent (CDC* pDC, int nIndex, CRect rect,BYTE state);

In Initialise(), you define default size of the well, number of columns, number ofrows, and the look and feel of the well control. There are currently only two kinds of look and feel for this well control, one is common Windows control look and one is Office 2000 style. GetWellName() is a very simple function to return a name of current select well.  The key function of this well control is DrawCellContent(), which draws content of each well.

There are two scenarios to use CSVizWellCtrl. One use is in popup windows and the other is use in dialogs. The four example well controls demonstrate both of them. The CSVizArrowWell is also good example code to show how to use bitmap resource in drawing the cell content.

  1. To use in a popup window (like the CSVizColorPopupWell,

    ) you have to use helper classes to pup up the well control windows. For CSVizColorWell , it is CColorPikcer and for CSVizArrowWell , it is CArrowPicker . You should create the well control window in the OnClicked() function of
    and CArrowPicker . In this case the parent window of well control is the helper class window.

    new CSVizArrowWell(CPoint(rect.left, rect.bottom), // Point to display popup
    	GetArrow(), // Selected arrow
    	this , // parent
  2. To use as a button. You don't need to create the control in your code. Using class wizard or manually add

    DDX_Control(pDX, IDC_YOUR_WELLBTN, m_Yourwellbtn);

    to the dialog's DoDataExchange(CDataExchange* pDX) function. And in this case, well control's parent is the dialog class.

Points of Interest

This well control is derived from CButton instead of CWnd directly. It is convenient when you use it in dialog based application, because you can use the standard DDX_Control() function. It can also be used as popup window like

will do.

Using bitmap resources, this well control can be used as toolbar in a dialog or you may create a control bar with a well control in it.

The CSVizColorWell itself might be useful for customizing the filling brush of GDI+. It supports the configuration of GLinearGradientBrush, PathGradientBrush, TextureBrush and HatchBrush.

To Do List

  • Record customized color in the color well
  • Integrate color dropper like Photoshop and FrontPage 2000


Some great ideas of the color picker and general well control come from the posts of Chris Maunder,  Alexander Bischofberger, Paul Wilkerson, and Geir Arne Trillhus. All appreciative feedback should also be passed to them, complaints to me. Those contributions can also be found in CodeProject.

License Agreement

This code may be used in compiled form in any way you desire (including commercial use). The code may be redistributed unmodified by any means providing it is not sold for profit without the authors written consent, and providing that this notice and the authors name and all copyright notices remains intact.

This software is provided "as is" without express or implied warranty. Use it at your own risk!


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


About the Author

Tao Zhu
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralRelease EXE doesn't show arrows Pin
Super Garrison9-Feb-11 18:06
memberSuper Garrison9-Feb-11 18:06 
GeneralI will be happy to know how to programm a modal loop for a menu Pin
Sanjit Rath3-Oct-04 9:11
memberSanjit Rath3-Oct-04 9:11 
QuestionWell control? Pin
Philippe Lhoste3-Dec-02 1:47
memberPhilippe Lhoste3-Dec-02 1:47 
AnswerRe: Well control? Pin
tao6-Dec-02 12:18
membertao6-Dec-02 12:18 
AnswerRe: Well control? Pin
OMalleyW19-Aug-05 6:09
memberOMalleyW19-Aug-05 6:09 
GeneralCool Pin
Norm Almond25-Nov-02 21:59
memberNorm Almond25-Nov-02 21:59 
GeneralMFC7.0 Issue Pin
tao25-Nov-02 15:03
membertao25-Nov-02 15:03 

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 | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 25 Nov 2002
Article Copyright 2002 by Tao Zhu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid