Click here to Skip to main content
Click here to Skip to main content

Owner-Draw Control Example: A Color Table Generator

, 4 Feb 2002
Rate this:
Please Sign up or sign in to vote.
A control for generating colour gradients
<!-- Download Links -->

Introduction

In creating a product for a client, we needed to show a gradation of color to represent confidence intervals in an audio spectral analysis (when the product is released, this page will show an example of the usage of such a table, but I can't show it right now). The idea is that colors would be more intense at the high-confidence-level analysis level, and fade to white at the zero-confidence level. The problem was to get a nice gradation that worked at different resolutions, and also deal with the fact that the eye's response is somewhat nonlinear. I did not favor typing in a table and experimenting "by hand" and the idea that I would have to use something like PowerPoint or Corel PhotoPaint to create this, and hand-translate to C/C++ did not appeal either. So I wrote a little utility program that could create and read RGB declarations suitable for inclusion in a C/C++ source file.

After having created it, I cleaned up the code a bit and decided to publish it as an example of owner-draw controls. One of the controls, the owner-draw button, is actually detailed in a companion essay on A Better Bitmap Button. The other control, an owner-draw ListBox, appears in another guise in my essay on A Logging ListBox Control. 

The ComboBox is interesting in that it is owner-draw with LBS_HASSTRINGS whereas the ListBox is owner-draw without LBS_HASSTRINGS, so two different styles can be studied.

An example of the control is shown below. 

Note that the selection highlighting in the ListBox does not extend across the entire entry (which would not make sense, given the desire to show a color), and the selection highlight is grayed out because the ListBox does not currently have the focus. An array of buttons allows immediate selection of common R, G and B values. In the ListBox, the only value stored is the COLORREF value and the string and color are generated at draw time; in the ComboBox, the ItemData stores the COLORREF and the string value stores the name, but the color swatch and color values are generated at draw time. The sample color swatch area represents a simple CStatic and the color is drawn via a simple OnEraseBkgnd handler.

Since this was originally constructed as a Quick & Dirty solution to a specific problem, I did not not apply all my standard production-quality techniques (such as keeping all English-language strings in the STRINGTABLE) so it is not representative of what I consider customer-deliverable code, but it is a close approximation.

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

About the Author

Joseph M. Newcomer

United States United States
No Biography provided

Comments and Discussions

 
QuestionIs this project still active? PinmemberRedDk30-Apr-14 6:08 
Generalcomplie error Pinmemberkinghei17-Sep-05 0:23 
GeneralRe: complie error PinmemberJoseph M. Newcomer17-Sep-05 6:19 
GeneralRe: complie error PinmemberJoseph M. Newcomer17-Sep-05 14:31 
In the interest of precision, note that what you reported was *not* a compiler error, but a link error, a quite different problem.
Generalreadme.txt file missing PinmemberJasonDoucette8-Apr-04 4:55 
GeneralRe: readme.txt file missing PinmemberJoseph M. Newcomer8-Apr-04 6:01 
Generalread rgb compose value PinmemberJordan31-Mar-02 15:04 
GeneralRe: read rgb compose value PinmemberJoseph M. Newcomer31-Mar-02 17:00 
QuestionWhy is this rated so low? PinmemberNish [BusterBoy]5-Feb-02 20:01 
AnswerRe: Why is this rated so low? PinmemberSenkwe Chanda5-Feb-02 20:28 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]5-Feb-02 20:37 
GeneralRe: Why is this rated so low? PinmemberNemanja Trifunovic6-Feb-02 8:01 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 8:21 
GeneralRe: Why is this rated so low? PinmemberNemanja Trifunovic6-Feb-02 8:37 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 8:39 
GeneralRe: Why is this rated so low? PinmemberBill Leibold6-Feb-02 9:03 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 9:10 
AnswerRe: Why is this rated so low? Pinmemberpeterchen6-Feb-02 7:54 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 8:20 
AnswerRe: Why is this rated so low? PinmemberChris Losinger6-Feb-02 8:10 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 8:18 
GeneralRe: Why is this rated so low? PinmemberBill Leibold6-Feb-02 9:06 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 9:12 
GeneralRe: Why is this rated so low? PinmemberBill Leibold6-Feb-02 9:57 
GeneralRe: Why is this rated so low? PinmemberNish [BusterBoy]6-Feb-02 16:03 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 5 Feb 2002
Article Copyright 2002 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid