tutorial 33: richedit control: basics
there are lots of request on tutorials about richedit controls. finally i have played with it enough to think i can write tutorials about it. so here it is: the first richedit tutorial. the tutorials will describe nearly everything there is to know about richedit control or at least as much as i know it. the amount of information is rather large so i divide it into several parts, this tutorial being the first part. in this tutorial, you'll learn what a richedit control is, how to create it and how to load/save data to/from it.
download the example.
theory
a richedit control can be thought of as a souped-up edit control. it provides many desirable features that are lacking from the plain simple edit control, for example, the ability to use multiple font face/size, multiple-level undo/redo, search-for-text operation, ole-embedded objects, drag-and-drop editing support, etc. since the richedit control has so many features, it's stored in a separate dll. this also means that, to use it, you can't just call initcommoncontrols like other common controls. you have to call loadlibrary to load the richedit dll.
the problem is that there are three versions of richedit control up till now. version 1,2, and 3. the table below shows you the name of the dll for each version.
| dll name | richedit version | richedit class name |
|---|---|---|
| riched32.dll | 1.0 | richedit |
| riched20.dll | 2.0 | richedit20a |
| riched20.dll | 3.0 | richedit20a |
you can notice that richedit version 2 and 3 use the same dll name. they also use the same class name! this can pose a problem if you want to use specific features of richedit 3.0. up to now, i haven't found an official method of differentiating between version 2.0 and 3.0. however, there is a workaround which works ok, i'll show 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 is loaded, it registers the richedit window class. thus it's imperative that you load the dll before you create the control. the names of the richedit control classes are also different. now you may have a question: how do i know which version of richedit control should i use? using the latest version is not always appropriate if you don't require the extra features. so below is the table that shows the features provided by each version of richedit control.
| feature | version 1.0 | version 2.0 | version 3.0 |
|---|---|---|---|
| selection bar |
x |
x |
x |
| unicode editing |
x |
x | |
| character/paragraph formatting |
x |
x |
x |
| search for text |
forward |
forward/backward |
forward/backward |
| ole embedding |
x |
x |
x |
| drag and drop editing |
x |
x |
x |
| undo/redo |
single-level |
multi-level |
multi-level |
| automatic url recognition |
x |
x | |
| accelerator key support |
x |
x | |
| windowless operation |
x |
x | |
| line break |
crlf |
cr only |
cr only (can emulate version 1.0) |
| zoom |
x | ||
| paragraph numbering |
x | ||
| simple table |
x | ||
| normal and heading styles |
x | ||
| underline coloring |
本文关键:iczelion asm
|