Solved

Font styles in CRichEditCtrl

Posted on 1997-08-29
9
604 Views
Last Modified: 2013-12-03
I need to display a few text strings in CRichEditCtrl in format:
<property name>: <property value>
Example:
      Name: Tom Ross
      SSN: 111-11-1111
My problem is that I have to display propery as "bold" and value as "italic". CRichEditCtrl class supply methods to change font style only for selected text, but I can not afford do it this way since user will
flashes when text would selected/deselected.


0
Comment
Question by:gelbert
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1305230
Did you try this way (pseudo-code):
 SetSelectionCharFormat(BOLD)
 Write property name
 SetSelectionCharFormat(ITALIC)
 Write property value
 Loop till no more properties
Since you change the style just before writing, you don't need to select any text, so it shouldn't flash.

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305231
Thanks for answer but I need additional information.
To show text in the Rich Edit control I from CStringArrays which I have I do following:
 
int iCount = pNames->GetSize() - 1;

 // make sure that array is not empty
 if ( -1 != iCount )
 {
       CString sText = "";
       for( int i = 0; i < iCount; i++ )
       {
      sText += ( pNames->GetAt(i) + ": " + pValues->GetAt(i) + "\n" );
       }

     // do not add next line symbol to last line
    sText += ( pNames->GetAt(iCount) + ": " + pValues->GetAt(iCount) );

    SetWindowText( sText );
}

So where od you suggest I should make SetSelectionCharFormat() call?
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1305232
You cannot apply my solution to this code.
You must find a good way for your needs to write each piece of the text char-by-char, not with SetWindowText().

Did you try your solution but adding SetRedraw(FALSE) in the beginning and SetRedraw(TRUE) before returning?
This might prevent the redraw of the richedit control after each selection.

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305233
I have some general guesses in which direction should I look, so I keep trying ( like now I trying to display text in OnDraw() using TextOut() to display text and SelectObject() to change font, for now it does not work).
     What I am looking is working advice how to get where I want to be ... ( Have text displayed in RichEditCtrl with some words in pne font and other words in another or different style ).  Thanks for your attempt to help me, but I need more then guess.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Author Comment

by:gelbert
ID: 1305234
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
davmarc earned 150 total points
ID: 1305235
Another idea that has just come up...put your text in RTF format into the clipboard, and tell the richedit control to paste the content of the clipboard?

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305236
thanks Davide, it sounds like a good idea. Any sample code?
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1305237
I've found a cleaner solution: use CRichEditCtrl::StreamIn() to insert your RTF-compliant text in the control.
Tell me your E-Mail address if you want he full RTF official specification.

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305238
My email address is gelbert@interport.com. Thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 48
method notes when mouse over in eclipse 5 82
maven archtype selection in eclipse 1 53
FizzBuzz challenge 9 76
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

937 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

4 Experts available now in Live!

Get 1:1 Help Now