
Question on changing text color in CEdit Control
To change the text color of a edit control, override OnCtlColor and then use
pDC->SetTextColor. This pDC is passed to you in OnCtlColor. More info:
http://support.microsoft.com/support/kb/articles/Q117/7/78.asp
http://support.microsoft.com/support/kb/articles/Q132/0/80.asp
--
Ajay Kalra [MVP - VC++]
Note: Please post all replies to newsgroup only.
Quote:
> Hi All,
> I wonder where is the problem? I want to display a string of text with
> this color changed in an CEdit control inside a CDialog, but it
> doesn't work.
> My objective is to compare between 2 text files in 2 edit control,and
> to show their differences in different color.
> thanks a lot!
> Ray Zhao
> BOOL CFileCompareDlg::OnInitDialog()
> {
> CDialog::OnInitDialog();
> ......
> ....
> CString m_str("this is a test");
> CWnd* pWnd = GetDlgItem(IDC_EDIT1);
> CDC * pDC=pWnd->GetDC();
> if (pDC==NULL) AfxMessageBox("Cannot retrieve Device Context");
> COLORREF colorRef=pDC->SetTextColor(RGB(255,0,0));
> pDC->TextOut(10,10,m_str2,m_str2.GetLength());
> pDC->SetTextColor(colorRef);
> }