CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2006
    Posts
    31

    how to create rich edit control dynamically

    hey,
    I m using DLGITEMTEMPLATE to create dialog control dynamically. Using atom values i have been able to create edit control, static control, buttons, etc. I dont konw how to create a rich edit box. I could not find a reference for atom values of rich edit control.
    Plz help!!

    thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: how to create rich edit control dynamically

    To use a RichEdit control, you must first call AfxInitRichEdit2 to load the RichEdit 2.0 Control (RICHED20.DLL), or call AfxInitRichEdit to load the older RichEdit 1.0 Control (RICHED32.DLL).

    and

    The name of the Rich Edit 1.0 window class is RichEdit. Rich Edit 2.0 has both ANSI and Unicode window classes—RichEdit20A and RichEdit20W, respectively. To specify the appropriate rich edit window class, use the RICHEDIT_CLASS constant, which the Richedit.h file defines depending on the definition of the UNICODE compile flag.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Jun 2006
    Posts
    31

    Re: how to create rich edit control dynamically

    Err.. i m not into MFC. I m using WIN32 Api!

  4. #4
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: how to create rich edit control dynamically

    There are several versions of RichEdit controls. Here is what I do:
    Code:
    #include <richedit.h> 
    /* ==============================================
       Create a RTF control
       =============================================== */
    int RTFEDIT_Init(HWND hWndParent)
    {
        if (!hRTFLib)
          hRTFLib = LoadLibrary("RICHED32.DLL");
    
        if (!hRTFLib) {
            char szErr[255];
            wsprintf(szErr, "LoadLibrary RICHED32.DLL failed. Error code %ld", GetLastError());
            MessageBox(hWndParent, szErr, "Error", MB_OK );
            hRTFLib = NULL;
            return FALSE;
        }
    
        hRTF = CreateWindow("RICHEDIT",          // Class Name of RTF Edit
                            "",                  // Text of edit control
                            WS_CHILD   | WS_VISIBLE | ES_MULTILINE   |
                            WS_VSCROLL | WS_BORDER  |
                            ES_AUTOVSCROLL | ES_NOHIDESEL, // Window style
                            0, 0,                // Initially create 0 size,
                            0, 0,                // Main Wnd's WM_SIZE handler will resize
                            hWndParent,          // Use main parent
                            (HMENU)0,            // ID of zero (we don't care)
                            (HINSTANCE) GetWindowLong(hWndParent, GWL_HINSTANCE), // This app instance owns this window
                            NULL                 // Don't need data in WM_CREATE
        );
        SetFocus(hRTF);
    
        return TRUE;
    }
    
    /* =============================================
       Remove the Richedit control
       ============================================== */
    void RTFEDIT_Shutdown(void)
    {
       if (hRTF) {
          DestroyWindow(hRTF);
          hRTF = NULL;
       }
       if (hRTFLib) {
          FreeLibrary(hRTFLib);
          hRTFLib = NULL;
       }
    }
    I don't remember very well if you also need
    Code:
    #include <commdlg.h>
    InitCommonControls();
    I don't know how atoms are getting involved in the process.

  5. #5
    Join Date
    Jan 2008
    Posts
    178

    Re: how to create rich edit control dynamically

    Quote Originally Posted by olivthill
    [/code]
    I don't remember very well if you also need
    Code:
    #include <commdlg.h>
    InitCommonControls();

    A RichEdit has never been a common control !

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: how to create rich edit control dynamically

    Quote Originally Posted by Pravish
    hey,
    I m using DLGITEMTEMPLATE to create dialog control dynamically. Using atom values i have been able to create edit control, static control, buttons, etc. I dont konw how to create a rich edit box. I could not find a reference for atom values of rich edit control.
    I encountered a similar problem and was not able to solve it.

    Eventually, I created as many controls as I could using an in-memory DLGITEMTEMPLATE, and then resorted to ordinary CreateWindow() calls for the remaining controls.

    Sorry,
    Mike

  7. #7
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: how to create rich edit control dynamically

    Quote Originally Posted by Pravish
    Err.. i m not into MFC. I m using WIN32 Api!
    AfxInitRichEditX functions basically just load the DLL. That's all. So you can also just load the DLL as follows:
    In your InitInstance:
    Code:
    m_hRichEd20 = LoadLibraryA("RICHED20.DLL");
    In your ExitInstance:
    Code:
    if (m_hRichEd20)
    {
        FreeLibrary(m_hRichEd20);
        m_hRichEd20 = NULL;
    }
    And add the following member to your CWinApp:
    Code:
    HANDLE m_hRichEd20;
    See also http://www.codeguru.com/forum/showthread.php?t=294548
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured