Solved

Rich Edit - extract formatted text

Posted on 2001-07-09
11
523 Views
Last Modified: 2013-12-03
I need to be able to get the contents of a rich edit control.  specifically i need all of the text and to know where any bold and/or underlined text starts and ends.  I can use EM_STREAMOUT to get contents, but how do I just parse out text, bold, and underline data?
Thank You
0
Comment
Question by:marvinm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6265408
I think you'll have to write a simple RTF to plain text parser that ignores all RTF control sequences apart from bold and underline.

0
 
LVL 1

Author Comment

by:marvinm
ID: 6265433
Do you have any examples of doing this? (non-MFC)
Thank You
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 6265454
You need to use EM_GETCHARFORMAT message
and CHARFORMAT structure

The EM_GETCHARFORMAT message determines the current character formatting in a rich edit control.

EM_GETCHARFORMAT
wParam = (WPARAM) (BOOL) fSelection;
lParam = (LPARAM) (CHARFORMAT FAR *) lpFmt;

In CHARFORMAT structure dwMask field may has( or not has)
CFM_BOLD/CFM_UNDERLINE attribute.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 1

Author Comment

by:marvinm
ID: 6265491
Do I need to set the selection to one character and do this for each character position?
Thank You
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6266076
Whilst you could call EM_GETCHARFORMAT iteratively for each character this would obviously not be very efficent. Then again it would work and saving you writing a lot of code.


If you wanted to parse the RTF data, then you should read the section of MSDN entitled "Rich Text Format (RTF) Specification, version 1.6".
If you don't have MSDN, I can mail you the section.


Try opening an RTF file in a text editor you'll see the format is very simple. Its a header followed by text with control codes embeded.

All control codes start with a "\".
Bold on/off is "\b" and "\b0" respectively.
Underline on/off is "\ul" and "\ulnone" respectively.
All control codes sequences terminate with a space " ".
The \ character is represented by "\\"

Rob
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6267813
I don't recommend you make RTF parser. I 've made
this and it is read headpain.
>> Do I need to set the selection to one character and do this for each character position?

I don't see something wrong in this (may be a bit slow, but can make in 10 min, parse is MINIMUM 2 weeks of job,
and after that you find text, that use some added tags and
all again...
  But:  RTF doc
http://www.wotsit.org/wtext/rtf15.zip (Rich Text File Format v1.5)
http://www.wotsit.org/wtext/rtfadd97.zip (Word 97 Addendum)
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6268324
It really depends on exactly what Marvin wants to do.

If he has text in a control and then needs to establish the formating of a particular character then yes EM_GETCHARFORMAT is the thing for him.

Using EM_GETCHARFORMAT for a more complex situation may work or it may be prohibitively exepensive in terms of performance.

Writing a full rtf parser would indeed be a task and a half but remember, he only needs to extract bold & underline information.

Rob
0
 

Expert Comment

by:chandas
ID: 6268961
Rob, would he really have to call EM_GETCHARFORMAT for each letter? I think maybe he could select a word at a time using GetSel(...). Maybe he could just look for space characters to break at each word and then select a word at a time.

Just my $0.02

Chandas
0
 
LVL 1

Author Comment

by:marvinm
ID: 6270783
This should be the easiest way to accomplish my goal.  There will not be much text to get, so efficiency is not a major concern.
Thanks to all - mm
0
 

Expert Comment

by:chandas
ID: 6276763
It would help if you awarded points for the comment that helped you out
0
 
LVL 1

Author Comment

by:marvinm
ID: 6276834
I DID!  AlexVirochovsky suggested using EM_GETCHARFORMAT which is easier than writing a RTF parser.  robpitt's comments were informative, and certainly the more thourough approach, but that is not the direction I am taking.  I have not implemented this yet as I have been pulled into a different project, but this will be my approach when I return to it.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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