Solved

Color text in a rich edit control

Posted on 2004-09-11
6
377 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

17 Experts available now in Live!

Get 1:1 Help Now