RTF File Handling

Environment: Visual C++ 6, richedit controls

Introduction

I needed a dialog box app based on the RichEdit control. I searched over the Net and I found Jeremy Iverson's article. I downloaded the code and studied it. It was not what I needed, but it was a good starting point.

So, my app is a kind of an RTF word processor. It has menus, toolbar, and a status bar. You can print the file, open, and save a file. You can choose any fonts you want from the Edit, Format Font menu. If you start to close a file and you haven't saved it, the program asks whethe 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, the opened file's path appears. If you want to save your file with the name of an existing one, my program asks whether you want to overwrite the file. My program has an accelerator table taken from MSDN sample Mfccalc(CCalcDlg::CCalcDlg(...)). The code from OnSize is patially taken from the MSDN sample Ftptree:CFTPTREEDlg::OnSize(...). I have limited the text to 100,000,000 characters.

CMyRichEditCtrl is derivated from the CRichEditCtrl class. This class has the following functions:

Code to Use Produces This Effect
void SetRtf(CFile* pInputFile );
Inserts the file's content. This function is taken from Jeremy Iverson's article and modified.
void SetSelectionBold();
Sets the selection to bold
void SetSelectionItalic();
Sets the selection to italic
void SetSelectionUnderline();
Sets the selection to be underlined
void SetColour();
Displays a color selection dialog box and sets the selection to the chosen color (if OK is pressed).
void SetColor(COLORREF clr);
Sets the CFontDialog color box
void SetParagraphLeft();
Sets the current paragraph to be left aligned
void SetParagraphRight();
sets the current paragraph to be right aligned
void SetParagraphCenter();
Sets the current paragraph to be centered
void SetParagraphBulleted();
Sets the current paragraph to be bulleted. This function is taken from Jeremy Iverson's article.
void SetFontName(CString sFontName);
Sets the font name. This function is taken from Jeremy Iverson's article.
void SetFontSize(int nFontSize);
Sets the font size. This function is taken from Jeremy Iverson's article.

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 while making this program. I needed a toolbar and status bar in my app and I have taken the code from an MSDN sample, dlgcbr32. What I haven't done is to create menu with icons because I don't know how to do it. Maybe you will succeed and let me know.

My program was compiled with Visual C++ 6, 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!

Downloads

Download source - 48 Kb


Comments

  • I need your help

    Posted by allooba on 11/12/2007 05:48am

    I tried to create rich text program using VC++. but I need when user press some keys in keyboard, I must show "dots" in screen. can you help me how to Handel the input from keyboard please. thanks. my email: alloob2@hotmail.com

    Reply
  • Little Problem

    Posted by Legacy on 09/03/2003 12:00am

    Originally posted by: Muhammad Khalid Noor

    void CMyRichEditCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
    {

    CMenu mnu;
    mnu.LoadMenu(IDR_MENU2);
    mnu.GetSubMenu(0)->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,AfxGetMainWnd());

    }


    OR


    Add following line if u r using Right Button Down Hanlder.

    ClientToScreen(&point);

    void CMyRichEditCtrl::OnRButtonDown(UINT nFlags, CPoint point)
    {

    CMenu mnu;
    mnu.LoadMenu(IDR_MENU2);
    mnu.GetSubMenu(0)->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,AfxGetMainWnd());

    CRichEditCtrl::OnRButtonDown(nFlags, point);
    }

    Reply
  • rtf and showing tables and printing

    Posted by Legacy on 08/25/2003 12:00am

    Originally posted by: Leon

    Hi
    how can i display tables and boxes in rtf file and printing them?im stuk with that problem few weeks please help me
    thanx

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds