Click here to Skip to main content
13,833,837 members
Click here to Skip to main content
Add your own
alternative version


56 bookmarked
Posted 2 Apr 2003
Licenced CPOL

CRichEditCtrl revised

, 2 Apr 2003
Rate this:
Please Sign up or sign in to vote.
A derived CRichEditCtrl class which focuses on streaming and on the visual aspects of formatting. Also includes the use of the link-formatting.
<!-- Download Links --> <!-- Article image -->

Sample Image - CRichEditCtrlGS.jpg

<!-- Add the rest of your HTML here -->

CRichEditCtrl revised

This heir of the MS-RichEditCtrl class has its main emphasis on support for visual appearance and streaming functionality, like CStrings, CbyteArrays, resources and files. Although some features like font or colour dialogging were tempting, I did not put it into the class, these are provided in the sample application. This is because I use this class in a static library, and there the access to the GUI is restricted.

Never mind, I think there is a lot that will help you, when dealing with CRichEditCtrl.

The source code comes with a help file in CHM-format. It contains the documentation of the CRichEditGS class. You need Internet Explorer V4.0 or higher to get access to that file.
Thanks to the people of FAR form The Helpware Group for their fine programm.

To use this class follow the usual wizardry. That is:
 • create a CRichEditCtrl with ResourceWizard
 • create a member of that control (not its content) with ClassWizard
 • copy the files "RichEditCtrlGS.cpp/h" into your project directory with CopyWizard.
 • replace all occurences of CRichEditCtrl by CRichEditCtrlGS with ReplaceWizard
 • include the headerfile "RichEditCtrlGS.h" either in stdafx.h or your dialogs/form/view header file. Sorry no IncludeWizard, so use the keyboard.

First of all, do not worry how to bind to RichEdit version 2 or version 3. This is done by some magic in the operating system.
The sample program was developed with Visual C++ Service Pack 5 and is running on WIN98SE and W2K equally well. Although the visual appearance of the links in WIN98SE is not that what I expected.
So if you have updated your operating system and your compiler in the last few years, chances are good that you may use the features of Richedit version 2.0.

You can use a CRichEditCtrl as a static control, when you deactivate this window. There you have all the formatting features of a rich text by just streaming in a resource.
How?. Well write a rich formatted text and save it as file into you res-directory (use the example application for that purpose).
After that open the resource editor. Tell it to import a new ressource. Select your newly created file and when the editor asks for the resource type give it the name RTF.
In your application code you should set the background colour of that CRichEditCtrl to COLOR_BTNFACE. Then call the stream in function for the resources of your derived CRichEditCtrl class (or SetRTF if you use mine).
Remember that a deactivated window will not get or send any message! So you will never get notified when the user hovers over a link.

While there is support from the operating system, there is no support from class wizard. So if you want support for the EN_LINK message notification for instance, tell class wizard that you need assistance for let's say EN_PROTECTED. After letting the class wizard do the job, load your source files and change every occurence of protected to link. Keep in mind to preserve capitals in this case. Then do the coding.

See the sample application how it works.
See the source code what must be done to get it working.


aka Frequently Given Answers

General Purpose
 • I don't know.
 • Yes.
 • No.
 • Send me an e-mail with further details.
 • Have a closer look at the source code of the example provided.

 • The link bit can only be set by the application. It will not be saved, although it will be copied. If you need it for internet purposes only, consider to send the EM_AUTOURLDETECT message to your control. Remember, in this case you will lose all link bits set by your program. You still have to do the hard programming part of the EN_LINK notification message.
 • Actually it is working correctly. The queer behaviour comes from the fact, that the format styles of characters are flags, while the paragraph alignment is an enumeration. So there is no way to determine if a 3( = centered) results from 3 | 0 or 1(=left) | 2(=right) or 2 | 1 or any or-combination of 0,1,2,3. That's why the alignment of paragraphs gets flagged wrong when your selection stretches more than one paragraph. Morale: never or enumerated values.
 • This comes in quite handy if you use a database, where long binary datas are bound to a CByteArray variable.
 • According to Microsoft the justify alignment will not be displayed, it will be stored however. That is true. Also according to Microsoft the text will be displayed as being left aligned. I saw it once being displayed centered.

So if you have a question, have a look first at the FGA section. The answer might be already there.

Also of good help is the wordpad source code provided with VC++ and MSDN.

G. Steudtel


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

G. Steudtel
Software Developer (Senior)
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

Generalsetting the Text Height fails Pin
Member 31442507-Jun-11 20:40
memberMember 31442507-Jun-11 20:40 
GeneralScrollbars are not displayed Pin
MikeTheDwarf26-Sep-08 10:34
memberMikeTheDwarf26-Sep-08 10:34 
QuestionCan I use your source code? Pin
Member 255468227-Jun-08 8:36
memberMember 255468227-Jun-08 8:36 
AnswerRe: Can I use your source code? Pin
G. Steudtel30-Jun-08 11:18
memberG. Steudtel30-Jun-08 11:18 
GeneralRe: Can I use your source code? Pin
Member 25546823-Jul-08 7:43
memberMember 25546823-Jul-08 7:43 
QuestionHow to prevent image from resizing Pin
kanam77719-Mar-08 4:55
memberkanam77719-Mar-08 4:55 
GeneralVery useful ! Pin
Marc Dispa29-Sep-07 7:14
memberMarc Dispa29-Sep-07 7:14 
GeneralRe: Very useful ! Pin
G. Steudtel30-Jun-08 11:23
memberG. Steudtel30-Jun-08 11:23 
Questionhow to make the same text all have link ? Pin
meadow-jn27-Sep-07 23:10
membermeadow-jn27-Sep-07 23:10 
QuestionHow to set focus on links in richeditctrl through tab Pin
Shaffiq27-Sep-07 16:56
memberShaffiq27-Sep-07 16:56 
QuestionReplace and Copy Wizards???? Pin
rypo27-Jan-07 21:44
memberrypo27-Jan-07 21:44 
AnswerRe: Replace and Copy Wizards???? Pin
S Douglas27-Jan-07 22:42
professionalS Douglas27-Jan-07 22:42 
AnswerRe: Replace and Copy Wizards???? Pin
G. Steudtel30-Jun-08 11:26
memberG. Steudtel30-Jun-08 11:26 
GeneralATL activex or other rich text control Pin
cordoval22-Jan-07 18:19
membercordoval22-Jan-07 18:19 
Generalurls from rich edit control Pin
dkdsnaidu28-Apr-06 2:32
memberdkdsnaidu28-Apr-06 2:32 
GeneralWell done! Pin
FamousDetective25-Mar-06 16:55
memberFamousDetective25-Mar-06 16:55 
GeneralCRichEditCtrl and displaying margins. Pin
delphidab11-Feb-06 11:13
memberdelphidab11-Feb-06 11:13 
GeneralSearch and chage color for text in the control Pin
yuvald5-Oct-05 7:49
memberyuvald5-Oct-05 7:49 
Questionhow to unselect text Pin
vjedlicka1-Feb-05 11:49
membervjedlicka1-Feb-05 11:49 
AnswerRe: how to unselect text Pin
Sriram Chitturi3-Jun-07 6:42
memberSriram Chitturi3-Jun-07 6:42 
AnswerRe: how to unselect text Pin
DLui29-Nov-07 2:52
memberDLui29-Nov-07 2:52 
GeneralColumns in RicheditCtrl Pin
lvidaguren3-Nov-04 0:48
memberlvidaguren3-Nov-04 0:48 
QuestionHow to find width of text in RichEdit? Pin
Anonymous21-Jul-04 2:18
memberAnonymous21-Jul-04 2:18 
AnswerRe: How to find width of text in RichEdit? Pin
Filomela1-Oct-04 23:45
memberFilomela1-Oct-04 23:45 
GeneralRe: How to find width of text in RichEdit? Pin
Member 89460819-Jul-05 1:21
memberMember 89460819-Jul-05 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190114.1 | Last Updated 3 Apr 2003
Article Copyright 2003 by G. Steudtel
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid