How to Use RichEditControl 4.1 in CRichEditView

By Flaviu Marc (mesajflaviu)

Introduction

The last available version of Windows RichEdit control is 4.1. However, the MFC framework still uses older versions of this control. For example, MFC 6.0 uses RichEdit control 1, which is very obsolete and even newer MFC versions that shipped with Visual Studio 2005-2010 use RichEdit control 2 or 3.

How to Overcome This?

In order to use RichEdit control 4.1 in CRichEditView MFC class, and enjoy its new features, we can do the following steps:

Step 1

In the MFC application class (derived from CWinApp) load the MSFTEDIT.DLL library module, which contains RichEdit control 4.1.

BOOL CRichEdit41App::InitInstance()
{
   // Load RichEdit 4.1 library 
   HMODULE hRE41Module = ::LoadLibrary(_T("MSFTEDIT.DLL"));
   if(NULL == hRE41Module)
   {
      AfxMessageBox(_T("RichEdit 4.1 library could not be loaded"));
      return FALSE;
   }
   // ...
}

Step 2

In the MFC view class (derived from CRichEditView) constructor, set the window class name for RichEdit 4.1, which is "RICHEDIT50W".

// Note: MSFTEDIT_CLASS is not defined in MFC6.0 and older
#ifndef MSFTEDIT_CLASS
#define MSFTEDIT_CLASS L"RICHEDIT50W";
#endif

CRichEdit41View::CRichEdit41View()
{
   m_strClass = MSFTEDIT_CLASS;
}

Step 3

In the WM_DESTROY message handler, move below the base class method call.
Note: this step is necessary in MFC6.0 and older.

void CRichEdit41View::OnDestroy()
{
   // CRichEditView::OnDestroy(); // <-- move this line below
   COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
   if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
   {
      pActiveItem->Deactivate();
      ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
   }
   CRichEditView::OnDestroy(); // <-- moved from above
}

Demo Application

The project attached here demonstrates how to load RichEdit 4.1 in a simple MFC-based application, and then enjoy its features like multiple Undo/Redo.

Resources



Related Articles

Downloads

Comments

  • Good Article

    Posted by Tirumalarao on 04/30/2012 02:28am

    Can plz brief the code.....

    • Thank you ...

      Posted by mesajflaviu on 05/06/2012 10:45pm

      What kind of code do you need ? You have a demo project where you find the exemplified code ....

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds