How do I subclass the list box portion of a combo box?
The listbox portion of a combo box is of type COMBOLBOX (notice the "L"). Because the ComboLBox window is not a child of the ComboBox window, it is not obvious how to subclass the COMBOLBOX control. Luckily, under the Win32 API, Windows sends a message to the COMBOBOX (notice no "L") called WM_CTLCOLORLISTBOX before the list box is drawn. The lParam passed with this message contains the handle of the list box. For example:
LRESULT CFileUpdateCombo::OnCtlColorListBox(WPARAM wParam,
LPARAM lParam)
{
if ( ! m_bSubclassedListBox )
{
HWND hWnd = (HWND)lParam;
CWnd* pWnd = FromHandle(hWnd);
if ( pWnd && pWnd != this )
{
// m_ListBox is derived from CListBox.
m_ListBox.SubclassWindow(hWnd );
m_ListBox.SetOwner(this);
m_bSubclassedListBox = TRUE;
}
}
return (LRESULT)GetStockObject(WHITE_BRUSH);
}