Solved

Color text in a rich edit control

Posted on 2004-09-11
6
415 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

856 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