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
• I don't know.
• 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.