
Colour combo box used in Windows desktop
OK, here's how I'd do it...
I'd take my standard owner-draw combo box for colors, and add one more
entry, whose ItemData was 0xFF000000. This is based on knowing that
RGB(r,g,b) does not create a 0xFF in the high/order byte. Now, when
that item is displayed, I'd just skip displaying the color block.
Then I'd change the OnSelChangeColor method to check to see if the
itemdata of the new selection was 0xFF000000. If so, I'd pop up the
standard color dialog box. What you do after that is now up to you.
You might want to add the new custom color to the dialog box (in which
case, you may want to give the user the option of naming it!), or just
set it whereever the color was supposed to go, then discard it. If I
added to the combo box, I'd make it the current selection. Ideally,
you will either use the CBS_SORT style and perform some kind of
sorting based on the color (such that 0xFF000000 sorts last) or simply
insert the new color in the next-to-last position so "Other" remains
last.
(I've got an assortment of code samples for doing color selection
boxes on the CD-ROM that accompanies our book, "Win32 Programming" by
Brent E. Rector and Joseph M. Newcomer).
joe
Quote:
>I wish to create a colour combo box picker which can also display some
>text. The combo box will show some standard colours and if the user
>selectes the item 'Other' they get displayed the standard Windows
>colour dialog box.
>I know that if you make the combo box owner drawn then I can add the
>colours. But how do I then add the text to say 'Other'.
>Help appreciated.
Joseph M. Newcomer
http://www3.pgh.net/~newcomer