[MFC] Cum pot folosi RichEdit 4.1 in CRichEditView?

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

[MFC] Cum pot folosi RichEdit 4.1 in CRichEditView?

Post by mesajflaviu » 20 Feb 2012, 20:42

Problema
Ultima versiune de control RichEdit din Windows este 4.1. Totusi framework-ul MFC foloseste versiuni mai vechi in clasa CRichEditView.
De exemplu, MFC6.0 foloseste RichEdit 1.0 care este total depasit. Chiar si in versiuni mai noi, inclusiv cea din Visual C++ 2010, versiunea folosita este 2.0/3.0.

Rezolvare
  1. In clasa aplicatiei, incarc MSFTEDIT.DLL

    Code: Select all

    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;
       }
       //...
    }
  2. In constructorul din clasa view (derivata din CRichEditView) setam numele clasei fereastra pentru contolul RichEdit v4.1.

    Code: Select all

    // 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;
    }
Note
  1. In MFC6.0 este necesara o mica modificare in codul pus de wizard in handlerul mesajului WM_DESTROY.

    Code: Select all

    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
    }
  2. Am atasat o mica aplicatie demo in care puteti testa functii care nu sunt suportate in RichEdit 1.0/2.0, cum ar fi Undo/Redo multiplu.
Resurse
RichEdit41_demo.zip
(31.24 KiB) Downloaded 453 times

<< Back to MFC index



Post Reply