Click here to Skip to main content
12,761,421 members (34,500 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked
Posted 14 Jul 2005

An example editor with table and image support

, 15 Jul 2005
Rate this:
Please Sign up or sign in to vote.
Use the new version rich edit control 4.1 to support table and image in your editor.

Sample screenshot


TapEditor is just an editor application to show how to using the new documented msfedit.dll to support our editor to add a table.

There are some new features that the rich edit control has supported in this new version. Table is one of them. Now we use the code below to help your editor support table. For more information about richedit control 4.1, you can follow this link.

Using the code

  1. Create an editor where the base View is CrichEditView.
  2. In the InitInstance() function of your editor, add the following code to load msfedit.dll:
    // Initialize RichEdit control
    if (LoadLibrary(_T("MSFTEDIT.DLL")) == NULL)
        AfxMessageBox(_T("Could not load the RichControl Dll."), 
        return FALSE;
  3. In the PreCreateWindow function of the View, specify like this to tell the View to create the class RICHEDIT50W of the new richedit control version:
    BOOL CTapEditorView::PreCreateWindow(CREATESTRUCT& cs)
        BOOL bRes = CRichEditView::PreCreateWindow(cs); |= ES_SELECTIONBAR;
        cs.lpszClass = szClassRE; // Create RICHEDIT50W class
        return bRes;

    Please add this code in the top of the CPP View file.

    static const TCHAR szClassRE[] = TEXT("RICHEDIT50W");
  4. Now to insert table, add a new function like OnInsertTable for example, and specify code like this:
    void CTapEditorView::OnInsertTable() 
        CInsertTableDlg dlg;
        if(dlg.DoModal() == IDCANCEL)
        int rows = dlg.m_nRows,
        cols = dlg.m_nColumns;
        CString s = "{\\rtf1";
        CString s = "{\\rtf1";
        CString sTable = s + 
            "{\\f0\\froman\\fprq2\\fcharset0 Times New Roman;}"
            "{\\f1\\fswiss\\fcharset0 Arial;}}"
            "{\\*\\generator Msftedit;}\\viewkind4\\uc1";
        CString row,col;
        row = "file://trowd//trgaph108//trleft8//"  
              "trbrdrl//brdrs//brdrw10 file://trbrdrt//"
              "brdrs\\brdrw10 file://trbrdrr//brdrs//" 
              "brdrw10 file://trbrdrb//brdrs//brdrw10 \\"
        col = "file://clbrdrl//brdrw10//brdrs//clbrdrt//brdrw10//brdrs//clbrdrr//"
        CString endcell = "file://cell/";
        CString endrow = "file://row/";
        int i,j;
        int width = 8748/cols;
        CString sColw;
        // Loop for numbers of rows
            sTable += row;
            // Loop for number of columns
                sTable += col;
                sColw.Format(_T("%d"),width *(j+1));
                sTable += sColw;
            sTable += "file://pard//intbl";
                sTable += endcell;
            sTable += endrow;
        sTable += "file://par}";/
    #ifdef _UNICODE
        LONG len = sTable.GetLength() * 2;
        char* data = new char[len + 1];
        ClearString(sTable, data);
        SETTEXTEX st;
        st.codepage = 1200; 
        st.flags = ST_SELECTION | ST_KEEPUNDO;
        SendMessage(EM_SETTEXTEX, (WPARAM)&st, (LPARAM)(LPCTSTR)data);
        delete data;
        SetTextEX(m_hWnd, sTable, ST_SELECTION|ST_KEEPUNDO, 1200);
  5. To insert image, do again like above with the new function OnInsertImage, with the code below:
    void CTapEditorView::OnInsertImage()
        CString sFilter = "All image file|*.bmp;*.jpg;*.gif|"
           "Bitmap Files (*.bmp)|*.bmp|JPEG Files (*.jpg)|*.jpg|"
           "GIF Files (*.gif)|*.gif|";
        CFileDialog dlg(TRUE, NULL, NULL, 
        if(dlg.DoModal() == IDOK)
            CTapBitmap bmp;
                AfxMessageBox(_T("Could not load image."));
            CEnBitmap enBitmap;
            CBitmap Bitmap;
            if (enBitmap.Attach(bmp.GetBMP(), 0))
                IRichEditOle *pRichEditOle;
                pRichEditOle = GetRichEditCtrl().GetIRichEditOle();
                HBITMAP hBitmap = (HBITMAP)Bitmap;
                    CImageDataObject::InsertBitmap(pRichEditOle, hBitmap);
  6. Finally don’t forget to include the headers file.

    Include tapex.h file for inserting table.

    #include "tapex.h"

    And include TapBitmap.h, EnBitmap.h and ImageDataObject.h for inserting image.

    #include "TapBitmap.h"
    #include "EnBitmap.h"
    #include "ImageDataObject.h"

This example applies for VC++ 6 so you don’t need to add the richedit.h header file if you don’t want to have errors.

If you use Visual Studio .NET or VC++ 7, you don’t need to use tapex.h and tapex.cpp files. For more information, please use this link.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Vietnam Vietnam
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionBug Pin
xdchen2620-Feb-14 16:11
memberxdchen2620-Feb-14 16:11 
Questionhi,i want to change the size of object,what shall i do? Pin
lin986665215-Jan-13 15:37
memberlin986665215-Jan-13 15:37 
General3Q Pin
Member 962422226-Nov-12 2:04
memberMember 962422226-Nov-12 2:04 
Questionhow to change the width of the table? Pin
dqf8810-Nov-10 20:57
memberdqf8810-Nov-10 20:57 
QuestionHow to Include data into the Table Pin
Khathar21-May-10 21:56
memberKhathar21-May-10 21:56 
GeneralNice and useful, a lot of help to me Pin
dokde112310-May-09 17:47
memberdokde112310-May-09 17:47 
Questionhow to make it readonly? Pin
rupanu28-May-08 4:58
memberrupanu28-May-08 4:58 
I want to set some contents in the view and make it non-editable.
how to do it..
Generalwrite simple text Pin
sheladiya chetan11-Jul-06 1:07
membersheladiya chetan11-Jul-06 1:07 
Generali want to merge row of table Pin
sheladiya chetan10-Jul-06 23:43
membersheladiya chetan10-Jul-06 23:43 
Generali need to understand screept Pin
sheladiya chetan3-Jul-06 1:58
membersheladiya chetan3-Jul-06 1:58 
Questionhow to get a embed picture's data directly Pin
ironsideliu1-Jun-06 5:52
memberironsideliu1-Jun-06 5:52 
Questionhow to get data with bullets from editor Pin
cancerion25-Apr-06 21:17
membercancerion25-Apr-06 21:17 
GeneralTable and center text Pin
waldermort18-Mar-06 8:30
memberwaldermort18-Mar-06 8:30 
QuestionAnother bug - number of pages when print Pin
milanm7619-Feb-06 21:25
membermilanm7619-Feb-06 21:25 
AnswerRe: Another bug - number of pages when print Pin
xvnguyen19-Feb-06 21:34
memberxvnguyen19-Feb-06 21:34 
GeneralRe: Another bug - number of pages when print Pin
milanm7619-Feb-06 22:25
membermilanm7619-Feb-06 22:25 
AnswerRe: Another bug - number of pages when print Pin
valneformal15-Jan-11 4:01
membervalneformal15-Jan-11 4:01 
GeneralWell done, but one question Pin
benni1-Dec-05 1:22
memberbenni1-Dec-05 1:22 
QuestionHow to get one cell's content Directly? Pin
Hongjun Ge28-Sep-05 20:43
memberHongjun Ge28-Sep-05 20:43 
AnswerRe: How to get one cell's content Directly? Pin
taphan28-Sep-05 21:10
membertaphan28-Sep-05 21:10 
GeneralRe: How to get one cell's content Directly? Pin
Hongjun Ge29-Sep-05 17:55
sussHongjun Ge29-Sep-05 17:55 
GeneralRe: How to get one cell's content Directly? Pin
taphan29-Sep-05 18:22
membertaphan29-Sep-05 18:22 
QuestionHow to directly output the table Pin
qqz8-Aug-05 6:42
memberqqz8-Aug-05 6:42 
AnswerRe: How to directly output the table Pin
taphan8-Aug-05 22:49
membertaphan8-Aug-05 22:49 
GeneralRe: How to directly output the table Pin
qqz9-Aug-05 3:21
memberqqz9-Aug-05 3:21 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 15 Jul 2005
Article Copyright 2005 by taphan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid