Solved

Edit vs. Rich Edit Controls

Posted on 1998-10-26
5
241 Views
Last Modified: 2010-04-02
I'm wondering if the EDIT control can change text colors.  I've tried before with SetTextColor() using MFC, and never could get it to work.  Now I've recoded the entire thing WITHOUT MFC, and am wondering if I am just waisting my time...If it IS possible, could you let me know the correct syntax?  (of the entire process, if possible.)

Also, besides some OLE stuff, are there any major advantages to using RichEdit instead of Edit?
0
Comment
Question by:ichor
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:yonat
ID: 1176245
Besides the "OLE stuff", with rich edit control you can use different text styles (fonts, coloers, size, etc.) and you are not limited to 64K content.

And no,you can't change the color of an edit control.

0
 

Author Comment

by:ichor
ID: 1176246
Using the EDIT control, I can already change the font and size.  But there's no way to change the color of the text using just Edit (instead of RichEdit)?  

I was under the impression that using Windows COLORREF values that I could change RGB values of text, like I said before, using SetTextColor()

Although I never got it to work correct (it never worked at all, actually), I had once tried to use code like:

m_Color = GREEN;  //GREEN defined in .h file.
HDC hdc;
SetTextColor(hdc, m_Color);

Obviously, this did not work.  I'm still sure that I've seen color changing using SetTextColor() with just the Edit control though.  Maybe I'm thinking of something else?
0
 
LVL 5

Expert Comment

by:yonat
ID: 1176247
You can only have ONE font and size for the ENTIRE text in the edit control. In the rich edit control, each character can have a different style. I don't know of a way to change its color.
0
 
LVL 4

Accepted Solution

by:
pagladasu earned 70 total points
ID: 1176248
Of course, you can change the text color in an edit control using MFC. Assume that there is an edit control to which is mapped a control type of variable called m_edit.
Map the WM_CTLCOLOR message of your dialog box.
Add the following code in OnCtlColor() function.
HBRUSH CDilprnDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
             //my additions
      if(pWnd==&m_edit)
            pDC->SetTextColor(RGB(255,0,0));
             //my addition ends
      return hbr;
}

Try it and send  a feedback.
Thanks,
Pagladasu.

Regarding Rich edit controls, I think most of the comments apply.

0
 

Author Comment

by:ichor
ID: 1176249
Hmm...I'd like to give both of you points, but I don't think that's possible.  Thanks for your help, though!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now