Click to See Complete Forum and Search --> : how to create rich edit control dynamically
Pravish
January 30th, 2008, 01:07 PM
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
Marc G
January 31st, 2008, 11:40 AM
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.
Pravish
January 31st, 2008, 12:24 PM
Err.. i m not into MFC. I m using WIN32 Api!
olivthill
February 1st, 2008, 06:08 AM
There are several versions of RichEdit controls. Here is what I do:
#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 #include <commdlg.h>
InitCommonControls();
I don't know how atoms are getting involved in the process.
fred100
February 1st, 2008, 07:30 AM
[/code]
I don't remember very well if you also need #include <commdlg.h>
InitCommonControls();
A RichEdit has never been a common control !
MikeAThon
February 1st, 2008, 10:58 AM
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
Marc G
February 2nd, 2008, 02:33 AM
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:
m_hRichEd20 = LoadLibraryA("RICHED20.DLL");
In your ExitInstance:
if (m_hRichEd20)
{
FreeLibrary(m_hRichEd20);
m_hRichEd20 = NULL;
}
And add the following member to your CWinApp:
HANDLE m_hRichEd20;
See also http://www.codeguru.com/forum/showthread.php?t=294548
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.