Click here to Skip to main content
11,641,659 members (59,954 online)
Click here to Skip to main content

Owner-Draw Control Example: A Color Table Generator

, 4 Feb 2002 133.3K 1.1K 22
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

Share

About the Author

Joseph M. Newcomer
Retired
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

You may also be interested in...

Comments and Discussions

 
QuestionIs this project still active? Pin
RedDk30-Apr-14 6:08
memberRedDk30-Apr-14 6:08 
Generalcomplie error Pin
kinghei17-Sep-05 0:23
memberkinghei17-Sep-05 0:23 
GeneralRe: complie error Pin
Joseph M. Newcomer17-Sep-05 6:19
memberJoseph M. Newcomer17-Sep-05 6:19 
GeneralRe: complie error Pin
Joseph M. Newcomer17-Sep-05 14:31
memberJoseph 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 Pin
JasonDoucette8-Apr-04 4:55
memberJasonDoucette8-Apr-04 4:55 
GeneralRe: readme.txt file missing Pin
Joseph M. Newcomer8-Apr-04 6:01
memberJoseph M. Newcomer8-Apr-04 6:01 
Generalread rgb compose value Pin
Jordan31-Mar-02 15:04
memberJordan31-Mar-02 15:04 
GeneralRe: read rgb compose value Pin
Joseph M. Newcomer31-Mar-02 17:00
memberJoseph M. Newcomer31-Mar-02 17:00 
QuestionWhy is this rated so low? Pin
Nish [BusterBoy]5-Feb-02 20:01
memberNish [BusterBoy]5-Feb-02 20:01 
AnswerRe: Why is this rated so low? Pin
Senkwe Chanda5-Feb-02 20:28
memberSenkwe Chanda5-Feb-02 20:28 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]5-Feb-02 20:37
memberNish [BusterBoy]5-Feb-02 20:37 
GeneralRe: Why is this rated so low? Pin
Nemanja Trifunovic6-Feb-02 8:01
memberNemanja Trifunovic6-Feb-02 8:01 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 8:21
memberNish [BusterBoy]6-Feb-02 8:21 
GeneralRe: Why is this rated so low? Pin
Nemanja Trifunovic6-Feb-02 8:37
memberNemanja Trifunovic6-Feb-02 8:37 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 8:39
memberNish [BusterBoy]6-Feb-02 8:39 
GeneralRe: Why is this rated so low? Pin
Bill Leibold6-Feb-02 9:03
memberBill Leibold6-Feb-02 9:03 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 9:10
memberNish [BusterBoy]6-Feb-02 9:10 
AnswerRe: Why is this rated so low? Pin
peterchen6-Feb-02 7:54
memberpeterchen6-Feb-02 7:54 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 8:20
memberNish [BusterBoy]6-Feb-02 8:20 
AnswerRe: Why is this rated so low? Pin
Chris Losinger6-Feb-02 8:10
memberChris Losinger6-Feb-02 8:10 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 8:18
memberNish [BusterBoy]6-Feb-02 8:18 
GeneralRe: Why is this rated so low? Pin
Bill Leibold6-Feb-02 9:06
memberBill Leibold6-Feb-02 9:06 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 9:12
memberNish [BusterBoy]6-Feb-02 9:12 
GeneralRe: Why is this rated so low? Pin
Bill Leibold6-Feb-02 9:57
memberBill Leibold6-Feb-02 9:57 
GeneralRe: Why is this rated so low? Pin
Nish [BusterBoy]6-Feb-02 16:03
memberNish [BusterBoy]6-Feb-02 16:03 
GeneralRe: Why is this rated so low? Pin
Joseph M. Newcomer16-Feb-02 12:04
memberJoseph M. Newcomer16-Feb-02 12:04 

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 | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 5 Feb 2002
Article Copyright 2002 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid