Problem subclassing list of owner-drawn combobox
-
I have a ComboBox in which I am subclassing the list box (see my article Case-sensitive ComboBox[^]). I now have a requirement to make some of the items bold. This is easily done by using an owner-drawn combo box. However, when I subclass the list of an owner-drawn combo, the list itself becomes owner drawn. This is a problem as it means that the list would need to know about which items to bold, but the information is in the combo box (apart from the fact that it just makes the architecture messy). Has anyone come across this before? In a normal owner-drawn combo the drawing of the list items seems to be delegated to the combo, but I can't see a way of telling the subclassed list to do the same. Any ideas would be appreciated!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
-
I have a ComboBox in which I am subclassing the list box (see my article Case-sensitive ComboBox[^]). I now have a requirement to make some of the items bold. This is easily done by using an owner-drawn combo box. However, when I subclass the list of an owner-drawn combo, the list itself becomes owner drawn. This is a problem as it means that the list would need to know about which items to bold, but the information is in the combo box (apart from the fact that it just makes the architecture messy). Has anyone come across this before? In a normal owner-drawn combo the drawing of the list items seems to be delegated to the combo, but I can't see a way of telling the subclassed list to do the same. Any ideas would be appreciated!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
OK, I've sussed it. So, for everyone out there who is dying to know what the solution is, here it is: I have overridden
OnChildNotify
in my subclassed listbox (CListBoxCS
). I have then added the following code:switch (message)
{
case WM_DRAWITEM:
case WM_MEASUREITEM:
case WM_COMPAREITEM:
case WM_DELETEITEM:
// don't allow owner-draw operations in the list, but handle them in the combo
return FALSE;
}
return CListBox::OnChildNotify(message, wParam, lParam, pLResult);This then causes all the drawing to be handled by the combobox rather than by the subclassed listbox.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)