Solved

Font styles in CRichEditCtrl

Posted on 1997-08-29
9
601 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Author Comment

by:gelbert
Comment Utility
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
davmarc earned 150 total points
Comment Utility
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
Comment Utility
thanks Davide, it sounds like a good idea. Any sample code?
0
 
LVL 4

Expert Comment

by:davmarc
Comment Utility
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
Comment Utility
My email address is gelbert@interport.com. Thanks for your help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

771 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

12 Experts available now in Live!

Get 1:1 Help Now