• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

Color text in a rich edit control

I'm using VC 6.0, CFormView. I n my CView class, i have a rich edit control, in which at the push of a button, I want to change the text color to red. And when I scroll to another record in the database,i want this color text data must be saved also, so that when I scroll back to this record I modified using a button control, the text displays once again in red.
I have seen ways to changge text and background color in a CDialog based app,  but wondered about the specifics of using the CView class in a database app (ODBC). Thanks for any insight.
0
pigeonbr
Asked:
pigeonbr
  • 3
  • 2
2 Solutions
 
jkrCommented:
Check out http://www.codeguru.com/Cpp/controls/richedit/article.php/c2419/ ("RichEditCtrl Syntax Highlighting") - you'll probably only need a subset of the functionality described there, but it shows the way to go.
0
Independent Software Vendors: 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!

 
pigeonbrAuthor Commented:
All these examples are helping me a little to get the feel of this coloring text in an edit bob...Did a test with another example I found, and am able to color text in Rich Edit control, in a CDialog class , but when I try to apply the same logic to doing it as in my question in the CView class ODBC database form, things don't work to well.
I need to get a handle on my existing RichEdit control and apply the following code, which is based on creating the control at runtime, which I don't do...it already exists and is connected to the database thru ODBC.:


  CRichEditCtrl* pRichEdit = (CRichEditCtrl*)pWnd ;
     int nLines = pRichEdit->GetLineCount() ;

     //Changes the first line background to blue and text color to yellow.
     int nEnd = pRichEdit->LineLength(1) ;

     pRichEdit->SetSel(0, nEnd) ;

     CHARFORMAT2 cf;
     cf.cbSize = sizeof(CHARFORMAT2) ;

     cf.dwMask = CFM_BOLD|CFM_BACKCOLOR|CFM_COLOR;
     cf.dwEffects = CFE_BOLD ;
     cf.crBackColor = RGB(0, 0, 255) ;
     cf.crTextColor = RGB(255, 255, 0) ;
     pRichEdit->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf) ;

//*************************************

Ok..so, how do I get a pointer to my existing RichEdit Control, and what about CWnd ??
Can you help me out a little more please ? Thanks!
0
 
pigeonbrAuthor Commented:
Found a question that had what I needed to get most of my answer here:
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20418250.html

Here is my function in the CView class:
void CViewRichEditTestView::OnButton1()
{
     m_setbackcolor.SetSel(0,1000);//color will affect 1000 characters in the edit control
     CHARFORMAT2 cf;
     cf.cbSize = sizeof(CHARFORMAT2) ;
     cf.dwMask = CFM_BOLD|CFM_COLOR;
     cf.dwEffects = CFE_BOLD ;
     cf.crTextColor = RGB(255,0, 0) ;//set to red
     m_setbackcolor.SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf) ;      


}
Looks like I got it figured out pretty good, but when I change the color of the text to red, and go to another record, the color does not get saved to the database...anyone have any ideas ? If not I will split the points for your efforts. Thanks.
0
 
pigeonbrAuthor Commented:
Ok..looks like no one can go further on this one...point split and I will ask another question more precicely. Thanks for the help guys!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now