Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rich Edit - extract formatted text

Posted on 2001-07-09
11
Medium Priority
?
549 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 800 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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