You have to enable the transparent background mode for the DC in the WM_CTLCOLOR method BEFORE returning the new brush:
HBRUSH CSampleDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// !!! Set background transparent !!!
pDC->SetBkMode(TRANSPARENT); // <<<<<<<<< Items will be transparent, showing the new bk brush
if (pWnd->GetDlgCtrlID() == IDC_MYLISTBOX)
{
if(m_bGrayed)
return (HBRUSH)GetStockObject(GRAY_BRUSH);
else
return (HBRUSH)GetStockObject(WHITE_BRUSH);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
Regards, mYkel