Question on changing text color in CEdit Control 
Author Message
 Question on changing text color in CEdit Control

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);

Quote:
}



Fri, 12 Dec 2003 04:43:45 GMT  
 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);
> }



Fri, 12 Dec 2003 05:34:05 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to change the text color of a CEdit or static control

2. Changing the color of the selected text in a CEdit control

3. Changing text color in a CEdit box

4. Changing Background Color of CEdit - Problem With Double Clicking On Texts

5. change text color in CEdit

6. Colored text in CEdit derived control

7. Colored background and text in a CEdit control

8. Set text color for 1 line in a CEdit control (MultiLine)

9. Changing Backround Color and ReadOnly status in CEdit control

10. Changing the default background color of disabled control (CEdit)

11. Changing the color of a CEdit control

12. How to change background color of a dynamically created CEdit control

 

 
Powered by phpBB® Forum Software