Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC
Article

Enhanced rich edit control

Rate me:
Please Sign up or sign in to vote.
4.12/5 (19 votes)
13 Sep 2003CPOL3 min read 199.4K   4.1K   37   37
A rich edit control with lots of extra features
MyRtf.GIF

Introduction

I needed a dialog box app based on RichEdit control. I have searched over the Net and I found Jeremy Iverson's article. I downloaded the code and studied it. It was not what I have needed but it was a good start point. So, my app is a kind of a RTF word processor. It has menus, toolbar, status bar etc. You can print the file, open and save a file, you can choose any fonts you want from Edit--- Format Font. If you close a file and you didn't save it the program asks if you want to save the file; the program has tooltips; if text is selected the Cut and Copy buttons are enabled, the program updates the message from statusbar. On the title bar appears the opened file path. If you want to save your file with the name of an existing one my program will ask if you want to overwrite the file. My program has accelerator table taken from MSDN sample - Mfccalc - CCalcDlg::CCalcDlg(...).The code from OnSize is partially taken from MSDN sample Ftptree - CFTPTREEDlg::OnSize(...).I have limited the text to 100000000 characters. CMyRichEditCtrl is derived from CRichEditCtrl class.

Details

This class has the following functions:

  1. Calling this will insert the file content --- void SetRtf(CFile* pInputFile ); This function is taken from Jeremy Iverson's article and modified
  2. Set the selection bold --- void SetSelectionBold();
  3. Set the selection italic --- void SetSelectionItalic();
  4. Set the selection underlined --- void SetSelectionUnderline();
  5. Displays a color selection dialog box and sets the selection to the chosen color (if OK is pressed). --- void SetColour();
  6. This is for CFontDialog color box --- void SetColor(COLORREF clr);
  7. Sets the current paragraph to be left aligned---void SetParagraphLeft();
  8. Sets the current paragraph to be right aligned --- void SetParagraphRight();
  9. Sets the current paragraph to be centered --- void SetParagraphCenter();
  10. Sets the current paragraph to be bulleted void SetParagraphBulleted();This function is taken from Jeremy Iverson's article.
  11. Sets the font name ---void SetFontName(CString sFontName); This function is taken from Jeremy Iverson's article.
  12. Sets the font size --- void SetFontSize(int nFontSize); This function is taken from Jeremy Iverson's article.

Using the control

Here's how to use this control in a dialog.

  • Include CMyRichEditCtrl.cpp and CMyRichEditCtrl.h in your project
  • In the resource editor create a rich edit control with the following styles: Multiline, Vertical scroll, AutoVScroll , No hide selection, Want return , Border
  • Create a control member variable for this rich edit control in VC classwizard
  • In CYourApp::InitInstance(), include a call to AfxInitRichEdit(), otherwise you won't see anything.

I have learned a lot making this program. I needed a toolbar and status bar in my app and I have taken the code from MSDN sample --- dlgcbr32. What I haven't done is menu with icons because I don't know how to do it. Maybe you will succeed and if so, let me know.

Conclusion

My program was compiled with Visual C++ 6 and under Windows 95. You know the rule: you are free to use and modify this source code. If you make any enhancements, I would appreciate if you let me know. Of course, this control is provided as is, and no warranty is expressed or implied. Happy programming!

History

  • 14 Sep 2003 - Updated sourcecode

License

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


Written By
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionRussian alphabet in your richedit Pin
Ckito31-Oct-06 5:19
Ckito31-Oct-06 5:19 
Generalstatus bar size Pin
ruede26-Sep-05 5:45
ruede26-Sep-05 5:45 
GeneralInsert text Pin
Yulianto.27-Jan-05 14:47
Yulianto.27-Jan-05 14:47 
GeneralRe: Insert text Pin
Filomela31-Jan-05 23:35
Filomela31-Jan-05 23:35 
GeneralRe: Insert text Pin
Yulianto.1-Feb-05 14:23
Yulianto.1-Feb-05 14:23 
GeneralRe: Insert text Pin
Filomela7-Feb-05 22:32
Filomela7-Feb-05 22:32 
GeneralRe: Insert text Pin
Yulianto.10-Feb-05 14:11
Yulianto.10-Feb-05 14:11 
GeneralRe: Insert text Pin
Filomela15-Feb-05 22:50
Filomela15-Feb-05 22:50 
GeneralRe: Insert text Pin
Yulianto.16-Feb-05 15:01
Yulianto.16-Feb-05 15:01 
GeneralRe: Insert text Pin
Yulianto.17-Feb-05 14:29
Yulianto.17-Feb-05 14:29 
QuestionHow To hide and show a Editbox? Pin
steve chua11-Jun-04 6:38
steve chua11-Jun-04 6:38 
AnswerRe: How To hide and show a Editbox? Pin
Anonymous21-Jun-04 22:15
Anonymous21-Jun-04 22:15 
GeneralRe: How To hide and show a Editbox? Pin
Anonymous11-May-05 19:45
Anonymous11-May-05 19:45 
GeneralQuestion is about Richedit ctrl - not necessarily this one Pin
rajas5-Apr-04 15:03
rajas5-Apr-04 15:03 
GeneralRe: Question is about Richedit ctrl - not necessarily this one Pin
Filomela20-Apr-04 22:10
Filomela20-Apr-04 22:10 
GeneralI want to write any letter other than that I pressed in my keyboard Pin
Member 9754991-Apr-04 5:06
Member 9754991-Apr-04 5:06 
GeneralGetting WM_CHAR Message for CRichEditCtrl Pin
Member 9754991-Apr-04 0:12
Member 9754991-Apr-04 0:12 
GeneralRe: Getting WM_CHAR Message for CRichEditCtrl Pin
Manfred Staiger1-Apr-04 1:19
Manfred Staiger1-Apr-04 1:19 
GeneralRe: Getting WM_CHAR Message for CRichEditCtrl Pin
Member 9754991-Apr-04 5:11
Member 9754991-Apr-04 5:11 
Generalmemory leak Pin
vmelkon2-Feb-04 15:32
vmelkon2-Feb-04 15:32 
GeneralRe: memory leak Pin
Filomela4-Feb-04 20:39
Filomela4-Feb-04 20:39 
I don't know what to say.Now i don't have somuch time to check, but i will check.
GeneralRe: memory leak Pin
TallPeter10-May-04 9:23
TallPeter10-May-04 9:23 
Generalwonderful control.. deserves a dot net wrapper! Pin
TuringTest16-Jan-04 20:42
TuringTest16-Jan-04 20:42 
GeneralRe: wonderful control.. deserves a dot net wrapper! Pin
Filomela18-Jan-04 20:48
Filomela18-Jan-04 20:48 
GeneralRe: wonderful control.. deserves a dot net wrapper! Pin
TuringTest119-Jan-04 10:05
TuringTest119-Jan-04 10:05 

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.