Document directory
RichEdit control Basics
· Cricheditctrl implements MSN/QQ animated expressions
· Cricheditctrl implements MSN background, Font, and hyperlink
· Expert answers: two questions about RichEdit
· Plot in memo or RichEdit as needed
· Enable trichedit to support big5 internal codes in bcb3. 0
· Changing the cursor position of RichEdit
· Enable trichedit to support big5 internal codes
Theory
A RichEdit control can be thought of as a souped-up edit control. Use Multiple font and font sizes, multi-level Undo/Redo, text search, embedded OLE objects, and drag-and-drop support for editing. The RichEdit control has many functions, so it is stored in a separate DLL file. This means that if you want to use the RichEdit control, you cannot just call the initcommoncontrols function just like using other common controls. You must first use loadlibrary to load the RichEdit DLL file.
There is a problem here, that is, the RichEdit control has a total of three versions, versions 1, 2 and 3. The following table shows the corresponding DLL file names for each version.
DLL name |
RichEdit version |
RichEdit Class Name |
Riched32.dll |
1.0 |
RichEdit |
Richedw.dll |
2.0 |
RICHEDIT20A |
Richedw.dll |
3.0 |
RICHEDIT20A |
You will notice that versions 2 and 3 use the same DLL file name, and they also use the same class name! This will cause problems when you want to explicitly use the RichEdit 3.0 feature. So far, I have found a formal Method To differentiate versions 2.0 and. However, there is a solution that works well and I will show it to you later.
.data RichEditDLL db "RichEd20.dll",0
.....
.data?
hRichEditDLL dd ?
.code
invoke LoadLibrary,addr RichEditDLL
mov hRichEditDLL,eax
......
invoke FreeLibrary,hRichEditDLL
When the RichEdit DLL file is loaded, it registers the RichEdit window class. Therefore, the class names of the DLL. RichEdit control must be loaded before you create the RichEdit control. Now you may have a question: how can I know which version of the RichEdit control I want to use? If you do not need any special features, the latest version may be the most appropriate. The following table lists the features provided by each RichEdit version.
Function |
Release 1.0 |
Release 2.0 |
Release 3.0 |
Select items |
X |
X |
X |
Unicode editing |
|
X |
X |
Character section format |
X |
X |
X |
Text Search |
Forward search |
Forward/Backward Search |
Forward/Backward Search |
Embedded Ole |
X |
X |
X |
Drag and Drop Edit |
X |
X |
X |
Undo/Redo |
Single Stage |
Multilevel |
Multilevel |
Automatic URL Recognition |
|
X |
X |
Acceleration key support |
|
X |
X |
Non-window operations |
|
X |
X |
Branch character |
CRLF |
Cr |
Cr (Yes Simulation Version 1.0) |
Zoom |
|
|
X |
Paragraph numbering |
|
|
X |
Simple Table |
|
|
X |
Normal and heading styles |
|
|
X |
Underline coloring |
|
|
X |
Hidden text |
|
|
X |
Font binding |
|
|
X |
The above table is not comprehensive: I just listed the important functions.
Create a rchedit Control
After the DLL file is loaded, you can call createjavaswex to create the RichEdit control. when creating the control, you can use the edit control style and normal window style, except the es_lowercase, es_uppercase, and es_oemconvert style.
.constRichEditID equ 300.dataRichEditDLL db "RichEd20.dll",0
RichEditClass db "RichEdit20A",0....data?
hRichEditDLL dd ?hwndRichEdit dd ?.code.....invoke LoadLibrary,addr RichEditDLLmov hRichEditDLL,eax
invoke CreateWindowEx,0,addr RichEditClass
,WS_VISIBLE or ES_MULTILINE or WS_CHILD or WS_VSCROLL or WS_HSCROLL, /CW_USEDEFAULT,CW_USEDEFAULT
,CW_USEDEFAULT,CW_USEDEFAULT,hWnd,RichEditID,hInstance,0mov hwndRichEdit,eax
Set the default text and background color
Set text and Background The color may be a problem, but this problem has been fixed in the RichEdit control. To set the RichEdit background color, you need to send the em_setbkgndcolor message to the RichEdit control. The message has the following syntax.
Wparam = color option. If it is 0, it indicates that Windows uses the color value in lparam as the background color. If this parameter is not 0, Windows uses System Background color. Because we want to send this message to change the background color, we must set wparam to 0.
Lparam = Specify the colorref structure of the color to be set. It is valid only when wparam is 0.
For example, if I want to set the background to blue, I need to write the following code:
invoke SendMessage,hwndRichEdit,EM_SETBKGNDCOLOR,0,0FF0000h
To set the text color, the RichEdit control provides another message, which is em_setcharformat. Work The message control controls the format of a selected text or all body. The syntax of this message is as follows:
Wparam = format options:
Scf_all |
This operation affects all text in the control. |
Scf_selection |
This operation only affects the selected text. |
Scf_word or scf_selection |
This operation only affects the selected word. If the selected word is empty, only the insert point (cursor) is set to the position of the specified word. The scf_word mark must be used with scf_selection. |
Lparam = a pointer to the charformat or charformat2 structure, indicating the body format to be used. charformat2 is only available in RichEdit 2.0 and later. this does not mean that charformat2 must be used after RichEdit 2.0. if you do not need to use the new feature in charformat2, you can still use charformat.
CHARFORMATA STRUCT cbSize DWORD ? dwMask DWORD ? dwEffects DWORD ? yHeight DWORD ? yOffset DWORD ? crTextColor COLORREF ? bCharSet BYTE ? bPitchAndFamily BYTE ? szFaceName BYTE LF_FACESIZE dup(?) _wPad2 WORD ? CHARFORMATA ENDS
Field name |
Descript_ion |
Cbsize |
The RichEdit control uses this field to determine whether the structure version is charformat or charformat2. |
Dwmask |
BITs are used to specify the following members.
Cfm_bold |
The cfe_bold value in the dweffects idiom is valid. |
Cfm_charset |
Bcharset members are valid. |
Cfm_color |
The value of cfe_autocolor in crtextcolor and dweffects is valid. |
Cfm_face |
<Font face = "Ms sans Ser |
|