Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

FGAs

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.

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

License

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

Share

About the Author

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

Comments and Discussions

 
Generalsetting the Text Height fails PinmemberMember 31442507-Jun-11 19:40 
GeneralScrollbars are not displayed PinmemberMikeTheDwarf26-Sep-08 9:34 
Hi,
first - thanks for sharing this excellent piece of code.
Using your example I found some strange behavior: The application does not display any kind of scroll-bars. Even if the text entered exceeds the displayable area.
 
Do you have any idea about how to manage that?
 
Nevertheless, got my 5!
QuestionCan I use your source code? PinmemberMember 255468227-Jun-08 7:36 
AnswerRe: Can I use your source code? PinmemberG. Steudtel30-Jun-08 10:18 
GeneralRe: Can I use your source code? PinmemberMember 25546823-Jul-08 6:43 
QuestionHow to prevent image from resizing Pinmemberkanam77719-Mar-08 3:55 
GeneralVery useful ! PinmemberMarc Dispa29-Sep-07 6:14 
GeneralRe: Very useful ! PinmemberG. Steudtel30-Jun-08 10:23 
Questionhow to make the same text all have link ? Pinmembermeadow-jn27-Sep-07 22:10 
QuestionHow to set focus on links in richeditctrl through tab PinmemberShaffiq27-Sep-07 15:56 
QuestionReplace and Copy Wizards???? Pinmemberrypo27-Jan-07 20:44 
AnswerRe: Replace and Copy Wizards???? PinmemberS Douglas27-Jan-07 21:42 
AnswerRe: Replace and Copy Wizards???? PinmemberG. Steudtel30-Jun-08 10:26 
GeneralATL activex or other rich text control Pinmembercordoval22-Jan-07 17:19 
Generalurls from rich edit control Pinmemberdkdsnaidu28-Apr-06 1:32 
GeneralWell done! PinmemberFamousDetective25-Mar-06 15:55 
GeneralCRichEditCtrl and displaying margins. Pinmemberdelphidab11-Feb-06 10:13 
GeneralSearch and chage color for text in the control Pinmemberyuvald5-Oct-05 6:49 
Questionhow to unselect text Pinmembervjedlicka1-Feb-05 10:49 
AnswerRe: how to unselect text PinmemberSriram Chitturi3-Jun-07 5:42 
AnswerRe: how to unselect text PinmemberDLui29-Nov-07 1:52 
GeneralColumns in RicheditCtrl Pinmemberlvidaguren2-Nov-04 23:48 
QuestionHow to find width of text in RichEdit? PinsussAnonymous21-Jul-04 1:18 
AnswerRe: How to find width of text in RichEdit? PinmemberFilomela1-Oct-04 22:45 
GeneralRe: How to find width of text in RichEdit? PinmemberBart Mikulski19-Jul-05 0:21 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 3 Apr 2003
Article Copyright 2003 by G. Steudtel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid