Solved

Edit vs. Rich Edit Controls

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 106
mixing C++ & C# in Vis Studio 2013 7 141
Using Diagnostic tools in VS2015: Unresoved allocations 19 66
max float value 3 26
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

896 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

18 Experts available now in Live!

Get 1:1 Help Now