Solved

Edit vs. Rich Edit Controls

Posted on 1998-10-26
5
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 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