Click here to Skip to main content
Click here to Skip to main content

Enhanced rich edit control

, 13 Sep 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Filomela

France France
No Biography provided

Comments and Discussions

 
QuestionRussian alphabet in your richedit PinmemberCkito31-Oct-06 6:19 
Generalstatus bar size Pinmemberruede26-Sep-05 6:45 
GeneralInsert text PinmemberYulianto AKA goodmast3r27-Jan-05 15:47 
GeneralRe: Insert text PinmemberFilomela1-Feb-05 0:35 
GeneralRe: Insert text PinmemberYulianto AKA goodmast3r1-Feb-05 15:23 
GeneralRe: Insert text PinmemberFilomela7-Feb-05 23:32 
GeneralRe: Insert text PinmemberYulianto AKA goodmast3r10-Feb-05 15:11 
GeneralRe: Insert text PinmemberFilomela15-Feb-05 23:50 
GeneralRe: Insert text PinmemberYulianto AKA goodmast3r16-Feb-05 16:01 
GeneralRe: Insert text PinmemberYulianto AKA goodmast3r17-Feb-05 15:29 
QuestionHow To hide and show a Editbox? Pinmembersteve chua11-Jun-04 7:38 
AnswerRe: How To hide and show a Editbox? PinsussAnonymous21-Jun-04 23:15 
GeneralRe: How To hide and show a Editbox? PinsussAnonymous11-May-05 20:45 
GeneralQuestion is about Richedit ctrl - not necessarily this one Pinmemberrajas5-Apr-04 16:03 
GeneralRe: Question is about Richedit ctrl - not necessarily this one PinmemberFilomela20-Apr-04 23:10 
GeneralI want to write any letter other than that I pressed in my keyboard PinmemberAnonymous1-Apr-04 6:06 
GeneralGetting WM_CHAR Message for CRichEditCtrl PinmemberAnonymous1-Apr-04 1:12 
GeneralRe: Getting WM_CHAR Message for CRichEditCtrl PinmemberManfred Staiger1-Apr-04 2:19 
GeneralRe: Getting WM_CHAR Message for CRichEditCtrl PinmemberAnonymous1-Apr-04 6:11 
Generalmemory leak Pinmembervmelkon2-Feb-04 16:32 
GeneralRe: memory leak PinmemberFilomela4-Feb-04 21:39 
GeneralRe: memory leak PinmemberTallPeter10-May-04 10:23 
Generalwonderful control.. deserves a dot net wrapper! PinmemberTuringTest16-Jan-04 21:42 
GeneralRe: wonderful control.. deserves a dot net wrapper! PinmemberFilomela18-Jan-04 21:48 
GeneralRe: wonderful control.. deserves a dot net wrapper! PinmemberTuringTest119-Jan-04 11:05 

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 | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 13 Sep 2003
Article Copyright 2003 by Filomela
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid