views:

42

answers:

1

Hi,

I used the following overloaded method to change the text color to red in a listbox, in a Visual C++ MFC dialog based application. When I build the program in DEBUG mode, it works perfectly. But when I use the RELEASE mode the text color doesn't change. Why is this and how can I overcome this problem??

Thanks!!

HBRUSH MyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
  if(nCtlColor == CTLCOLOR_LISTBOX)
  {
     if(bChangeTextColor)
     {
       pDC->SetTextColor(RGB(255, 0, 0));
       return m_hRedBrush;
     }
  } 
  return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
+1  A: 

Can you try to call the base implementation CDialog::OnCtlColor before your custom code, like this:

HBRUSH MyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hBrush=CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if(nCtlColor == CTLCOLOR_LISTBOX)
    {
        if(bChangeTextColor)
        {
            pDC->SetTextColor(RGB(255, 0, 0));
            hBrush=m_hRedBrush;
        }
    } 
    return hBrush;
}

CDialog::OnCtlColor does some stuff internally which is skipped by your return inside of your function. It's only a very vague idea but I have always used OnCtlColor this way and never had a problem.

Slauma
Thanks for the reply, I'll try it out :)
Isuru