Visual c++ 更改cmbobox的文本和背景

Visual c++ 更改cmbobox的文本和背景,visual-c++,mfc,Visual C++,Mfc,我想给cmbobox的编辑框上色。但我想为CBS_下拉列表样式和CBS_下拉列表也这样做。 我凌驾 HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(CTLCOLOR_EDIT == nC

我想给cmbobox的编辑框上色。但我想为CBS_下拉列表样式和CBS_下拉列表也这样做。 我凌驾

HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

if(CTLCOLOR_EDIT == nCtlColor)
{
    pDC->SetTextColor(m_crAlertText);
    pDC->SetBkColor(m_crAlertBkg);
    hbr = m_hBrushAlert;
    pDC->SetBkMode(TRANSPARENT);
}

// TODO: Return a different brush if the default is not desired

return hbr;
}
但如果CComboBox有CBS_DROPDOWNLIST风格,这就不起作用了。。。为什么?

稍后编辑:

是的,我已经试过了:

HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

    //  if(CTLCOLOR_STATIC == nCtlColor)
    if(CTLCOLOR_EDIT == nCtlColor || CTLCOLOR_STATIC == nCtlColor)
{
    pDC->SetTextColor(m_crAlertText);
    pDC->SetBkColor(m_crAlertBkg);
    hbr = m_hBrushAlert;
    pDC->SetBkMode(TRANSPARENT);
}

// TODO: Return a different brush if the default is not desired

return hbr;
}
似乎不起作用。。。我不明白为什么…

引用:

CBS_下拉列表与CBS_下拉列表类似,不同之处在于编辑控件被显示当前 在列表框中选择

因此,无法更改编辑控件颜色的原因是,使用此样式时没有编辑控件。因此,如果(CTLCOLOR\u EDIT==nCtlColor)条件永远不会为真。您可能希望尝试测试
CTLCOLOR\u STATIC