|
-
January 30th, 2008, 02:07 PM
#1
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
-
January 31st, 2008, 12:40 PM
#2
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.
-
January 31st, 2008, 01:24 PM
#3
Re: how to create rich edit control dynamically
Err.. i m not into MFC. I m using WIN32 Api!
-
February 1st, 2008, 07:08 AM
#4
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.
-
February 1st, 2008, 08:30 AM
#5
Re: how to create rich edit control dynamically
 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 !
-
February 1st, 2008, 11:58 AM
#6
Re: how to create rich edit control dynamically
 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
-
February 2nd, 2008, 03:33 AM
#7
Re: how to create rich edit control dynamically
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|