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
This class has the following functions:
- Calling this will insert the file content ---
void SetRtf(CFile* pInputFile ); This function is taken from Jeremy Iverson's article and modified
- Set the selection bold ---
- Set the selection italic ---
- Set the selection underlined ---
- Displays a color selection dialog box and sets the selection to the chosen color (if OK is pressed). ---
- This is for
CFontDialog color box ---
void SetColor(COLORREF clr);
- Sets the current paragraph to be left aligned---
- Sets the current paragraph to be right aligned ---
- Sets the current paragraph to be centered ---
- Sets the current paragraph to be bulleted
void SetParagraphBulleted();This function is taken from Jeremy Iverson's article.
- Sets the font name ---
void SetFontName(CString sFontName); This function is taken from Jeremy Iverson's article.
- 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
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.
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!
- 14 Sep 2003 - Updated sourcecode