Building the Right Environment to Support AI, Machine Learning and Deep Learning
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.