dcsimg

A Color Combo Control

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


screen-shot

To draw items in different colours in a combo box is a little more involved than the usual subclassing routines that some may be used to. We actually need to capture the creation of the combo control. In order to do this, we need to first subclass our form while it is being created (using the SetWindowsHookEx api) and capture the WM_CREATE message for the combo as it's created. We then need to change the style of the combo to include CBS_OWNERDRAWVARIABLE). Once we have changed the style of the combo as it is created, we can release our existing subclassing.

Now, when the form is loaded, we again need to subclass the form and capture any WM_DRAWITEM for the combo - this allows us to interrupt the painting process for the combo and change the colour of each item as it is drawn.

Be sure to read through the code carefully! You may find that trying to debug the application can cause GPF's in VB (same as any other subclassing example) - so be careful out there!

Download zipped project and exe (10k)



Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date