I would like to change the text color of the text present in IDC_EDIT1 box when a new color is selected from the combo box. But it is now working,
OnCbnSelchangeComboColorBox :- Event Handler for Combo Box
m_Combo_Box :- Variable name for combo box.
m_text :- Variable name for IDC_EDIT1.

void CFontFormatter::OnCbnSelchangeComboColorBox()
{
int comboBoxSelectedItem = m_Combo_Box.GetCurSel();
if (comboBoxSelectedItem != LB_ERR) {
CString selectedColorText;
m_Combo_Box.GetLBText(comboBoxSelectedItem, selectedColorText);
if (selectedColorText == _T("Red"))
fontColor = RGB(255, 0, 0);
else if (selectedColorText == _T("Green"))
fontColor = RGB(0, 255, 0);
else if (selectedColorText == _T("Blue"))
fontColor = RGB(0, 0, 255);
CWnd* pEditControl = GetDlgItem(IDC_EDIT1);
if (pEditControl)
{
CDC* pDC = m_editText.GetDC();
pDC->SetTextColor(fontColor);
pEditControl->Invalidate();
pEditControl->UpdateWindow();
}
m_text.SetString(selectedColorText);
UpdateData(FALSE);
}
}
I have Tried through CWnd* and CDC*.
Here is one resource https://www.equestionanswers.com/vcpp/background-color-edit-static.php). They provide some code: