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.

I rarely include the readme.txt file in the zip files, since it is completely useless. It is generated by VS6, and contains nothing meaningful. Then, for reasons known only to the VS6 designers, it is included in the project. Ignore this; delete it from the project.

Not sure what you mean here. You can't read "directly" from a resource; you have to either use LoadBitmap (which messes up the colors), LoadImage (which does not) or FindResource/LoadResource/LockResource, which is just a hard way of doing LoadImage plus GetBitmapBits. Assuming you have 24-bit color, you have to locate the pixel value in the array of data bits and then you can use GetRValue on that COLORREF value. If you have a paletted bitmap image (8-bit color) it is more complex; you have to read the color map information and convert the 8-bit color value to an RGB value using the color map associated with the image. But there is no known way to read a resource "directly". I think there is a slight language problem here but I can't quite figure out what you meant by "I don't want to read color value ,then read one compose of color". Alas, I can't suggest how to do what this might be, or I could either explain how to do what you want or why what you want can't be done. I won't be available again until 10-Apr, so I won't be able to answer until after that date.

I am quite shocked by the rating this article has got. 1.8 from 5 votes. This is ridiculous. I mean it is a sad reflection on the rating system's inefficiency.

I believe that this surely deserves 4-plus!

Regards
Nish

p.s. Of course people don't really give a great deal of importance to the ratings, but it will get out of the filtered list of "pick of the day" and so on. And new CP visitors might actually think it's not worth a look. They might miss a decent article as this one is, merely because of the low rating.

I agree, great article. But I've noticed that sometimes an article gets a low rating because in general people are looking for a tutorial on how something is done. After they read the tutorial and get a feel for the code, they then download the source and check it out. That's when they rate it better. The above article is very good, but the author should have gone step by step in explaining how/why this and that works (aside from the comments in the code which are probably very good)

Perhaps you are right regarding the way attitude people take towards articles. But what most people do not understand is that Joe Newcomer is the ultimate Guru when it comes to Win 32 API or MFC stuff. In my opinion and a very strong one, he is the NUMBER ONE Guru on Code Project.

People should not expect him to write baby-level articles. His articles are often unorthodox stuff and very often a clear reflection of his own thinking. I was very much influenced by his writings on the use of UpdateData in dialogs.

Nish [BusterBoy] wrote:that Joe Newcomer is the ultimate Guru when it comes to Win 32 API or MFC stuff. In my opinion and a very strong one, he is the NUMBER ONE Guru on Code Project.

I haven't read (or rated) the article, because I'm not that much in UI programming (thank God). However, I don't like the "Guru" attitude. Guru is a religious term, and we are all mortal programmers. I like Mr Newcomer's articles, but if I didn't like some of them, I would have rated them low, guru or no guru.

You are right there Nemanja, but I still cannot accept a 1.8 rating for this one, that too after 5 votes. I know it might not deserve a 4 or a 5 [though I'd give it 4] but I am sure it deserves a lot more than 1.8.

Who defines whether a person is a "Guru" or not. Just because somebody posts often doesn't afford them the luxury of best ratings on their articles. I haven't yet rated this, but honestly do not know how to rate it so I will pass for now.

I always considered the sum(ratings) more meaningful than the average. It diversifies the "5.0" articles, gives a reasonable balance beetween "many low" and "a few high" votes, and hate ratings just don't work anymore.

Maybe not hate-ratings. But some people enjoy putting some articles down for whatever funny reasons they might have. But I get your point though. A 5-rated article with 3 votes would might not be much. But a 4.7 rated article with 40 votes would be pretty much okay, I guess.

why does this one deserve a 4+ ? it's a full solution to a very specific problem - a problem most of us will never encounter. for that reason alone, i wouldn't give it above a 4 (assuming the code isn't absolutely the most elegant code ever).

I think this has gone far enough for me. I was only trying to point out that the ratings are not always indicative of the quality of an article. It just happened to be this article. I don't see why I should keep advocating this cause. It does not seem to be working anyway!