Solved

Color text in a rich edit control

Posted on 2004-09-11
6
401 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 …
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

7 Experts available now in Live!

Get 1:1 Help Now