Solved

Font styles in CRichEditCtrl

Posted on 1997-08-29
9
609 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Title # Comments Views Activity
notReplace  challenge 53 142
conditional code and condition difference 9 84
sum28 challenge 31 115
Line meaning 9 88
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…
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…

820 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