Solved

Color text in a rich edit control

Posted on 2004-09-11
6
425 Views
Last Modified: 2013-11-20
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
Comment
Question by:pigeonbr
  • 3
  • 2
6 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 12034944
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
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 250 total points
ID: 12036423
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12036435
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!

 

Author Comment

by:pigeonbr
ID: 12045299
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
 

Author Comment

by:pigeonbr
ID: 12089755
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
 

Author Comment

by:pigeonbr
ID: 12142771
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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
canBalance challenge 34 104
Unix Command -- Challenging  question 7 101
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 113
Not needed 13 128
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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