Changing colours of a combo box (reposted)
-
Hi, I've subclassed CComboBox. I've setup the background and text colours called Invalidate(). Which works perfectly well with the edit box. It's when I dropdown it's crashing the app. I want to able to change the colour of the listbox part as well. Here's the code snippet:
BEGIN_MESSAGE_MAP(CComboEx, CComboBox) //{{AFX_MSG_MAP(CComboEx) ON_WM_CTLCOLOR_REFLECT() ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CComboEx message handlers HBRUSH CComboEx::CtlColor(CDC* pDC, UINT nCtlColor) { // TODO: Change any attributes of the DC here /* // TODO: Return a non-NULL brush if the parent's handler should not be called if(nCtlColor = CTLCOLOR_LISTBOX) { return OnCtlColor(pDC,this,nCtlColor); } */ pDC->SetTextColor(m_Text); pDC->SetBkColor(m_Background); pDC->SetBkMode(TRANSPARENT); m_brush.DeleteObject(); m_brush.CreateSolidBrush(m_Background); return m_brush; } HBRUSH CComboEx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor); return hbr; }
Thanks in advance, Alton