Steven Shih
Steven Shih

Reputation: 645

Stop OnCtlColor() changing combobox's (edit control)'s "text color"

The MFC combobox is really a wierd design.

I use "drop list" type combo box.

HBRUSH CValueInputDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)  
{
    HBRUSH hBrush = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR_STATIC || nCtlColor == CTLCOLOR_EDIT)
    {
        pDC->SetTextColor(RGB(255, 255, 255));  
        pDC->SetBkMode(TRANSPARENT);  
        hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
    }    
    return hBrush;
}

what I do is having all my CStatic and CEdit color WHITE.

but i discover that I also change the combobox's edit to white.

that is what I don't want.

that is what I don't want. and I can't stop it from

pWnd->GetDlgCtrlID() == IDC_COMBO

it is so unfriendly. this combo box.

Upvotes: 1

Views: 2281

Answers (1)

l33t
l33t

Reputation: 19966

The Edit box is a child of the combo box. Try this:

pWnd->GetParent()->GetDlgCtrlID() == IDC_COMBO

Upvotes: 4

Related Questions