Solved

Edit vs. Rich Edit Controls

Posted on 1998-10-26
5
261 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

696 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