Repository navigation
SysWin RichEdit Control
Home › All Categories › sys/win › sys/win/richedit › RichEd
Sends rich edit messages to a control by its handle: text, selection, formatting and RTF.
The RichEd namespace holds one function per rich edit message, plus a few helpers that load
RTF and set the font. Each takes the control's handle first, sends the message with
SendMessageW and returns what the control returns, so they work on any rich edit control: one
made with CWindow.AddControl( "RichEdit", ... ) (which loads Msftedit.dll and creates a
RichEdit50W control), the hRichEdit of a CRichEditCtx, or a rich edit control
in a dialog. CRichEditCtx wraps most of the same messages as members; use these functions when
all you have is a handle.
Character positions count characters from 0 at the start of the text. A range runs from its
start to just before its end, and an end of -1 means the end of the text, so SetSel( hCtrl, 0, -1 ) selects everything. The control keeps each paragraph end as one carriage return (13): the
positions count it as one character, while GetText and
GetTextLength report it as CR LF. Lines are lines as displayed; with word
wrap on, one paragraph can take several.
Structures. Many functions take a pointer to a Windows structure (CHARRANGE,
CHARFORMATW, PARAFORMAT, FINDTEXTEXW …). Set its cbSize first where it has one. The
CHARFORMAT2W and PARAFORMAT2 forms are accepted with a cast. Three parameter types are written
..FORMATRANGE, ..GETTEXTEX and ..GETTEXTLENGTHEX: the leading .. names the Windows
structure, not the namespace function of the same name; in your own code write FORMATRANGE.
Notifications. A rich edit control sends its parent only the notifications named in its event
mask (SetEventMask): ENM_CHANGE for EN_CHANGE, ENM_SELCHANGE
for EN_SELCHANGE, and so on. A new control has an empty mask.
Text parameters are wstring ptr or byref wstring: pass a literal, a ustring or a wstring.
Functions that return text return a ustring. Nothing here allocates anything you must free,
except the interface GetOleInterface returns.
#import "sys/win"
#import "sys/win/richedit"
using win, richeditA rich edit control that fills the window, filled from RTF. The caption follows the caret: line,
column and the selected text, from the control's EN_SELCHANGE notification.
#import "sys/win"
#import "sys/win/gui"
#import "sys/win/richedit"
using win, gui, richedit
const IDC_RICHEDIT = 101
declare function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
function main() as long
SetProcessDpiAwareness( PROCESS_SYSTEM_DPI_AWARE )
dim pWindow as CWindow = "RichEditFunctions"
dim hWin as HWND = pWindow.Create( NULL, "RichEdit", @WndProc )
pWindow.SetClientSize( 480, 260 )
pWindow.Center()
dim hRich as HWND = pWindow.AddControl( "RichEdit", hWin, IDC_RICHEDIT, "", 0, 0, 480, 260 )
pWindow.AnchorControl( IDC_RICHEDIT, ANCHOR_HEIGHT_WIDTH )
richedit.RichEdit.SetFont( hRich, "Segoe UI", 11 )
dim stx as SETTEXTEX
stx.flags = ST_DEFAULT : stx.codepage = CP_ACP
dim rtf as string = "{\rtf1\ansi Move the caret: the caption shows the {\b line}, the {\b column} and the {\i selection}.\par A second paragraph.}"
richedit.RichEdit.SetTextExW( hRich, @stx, cast( wstring ptr, strptr( rtf ) ) )
richedit.RichEdit.SetEventMask( hRich, ENM_SELCHANGE )
richedit.RichEdit.SetModify( hRich, 0 )
SetFocus( hRich )
return pWindow.DoEvents( SW_NORMAL )
end function
function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
select case uMsg
case WM_NOTIFY
dim pnm as NMHDR ptr = cast( NMHDR ptr, lParam )
if pnm->idFrom = IDC_RICHEDIT andalso pnm->code = EN_SELCHANGE then
dim psc as SELCHANGE ptr = cast( SELCHANGE ptr, lParam )
dim hRich as HWND = pnm->hwndFrom
dim nLine as long = richedit.RichEdit.ExLineFromChar( hRich, psc->chrg.cpMin )
dim nCol as long = psc->chrg.cpMin - richedit.RichEdit.LineIndex( hRich, nLine )
SetWindowText( hwnd, "line " & nLine + 1 & ", column " & nCol + 1 & _
", selected [" & richedit.RichEdit.GetSelText( hRich ) & "]" )
end if
return 0
case WM_DESTROY
PostQuitMessage( 0 )
return 0
end select
return DefWindowProcW( hwnd, uMsg, wParam, lParam )
end function
end main()Text
| Function | Does |
|---|---|
| GetText | Returns the control's text. |
| GetTextLength | Returns the length of the text, paragraph ends counted as two. |
| SetText | Replaces the text. |
| GetTextEx | Copies the text into a buffer, in a code page of your choice. |
| GetTextLengthEx | Measures the text in several ways. |
| SetTextExW | Sets the text or the selection from plain text or RTF. |
| GetTextRange | Copies a range of characters into a buffer. |
| GetLine | Returns one line. |
| GetLineCount | Returns the number of lines. |
| LineIndex | Returns the position at which a line starts. |
| LineFromChar | Returns the line that holds a character. |
| ExLineFromChar | Returns the line that holds a character, for any position. |
| LineLength | Returns the length of the line that holds a character. |
| GetLimitText, LimitText, SetLimitText | Reads or sets how much text the user can enter. |
| ExLimitText | Sets how much text the user can enter, above 64K. |
| GetTextMode, SetTextMode | Reads or sets rich or plain text and the undo levels. |
| GetModify, SetModify | Reads or sets the changed flag. |
Selection
| Function | Does |
|---|---|
| GetSel | Reads the selection. |
| SetSel | Selects a range of characters. |
| ExGetSel | Reads the selection into a CHARRANGE. |
| ExSetSel | Selects the range a CHARRANGE holds. |
| GetSelText | Returns the selected text. |
| ReplaceSel | Replaces the selection with text. |
| SelectionType | Tells what the selection holds. |
| HideSelection | Hides or shows the selection. |
| FindText | Finds text. |
| FindTextEx | Finds text and returns the range found. |
| FindWordBreak | Finds the next word break, or classifies a character. |
| CharFromPos | Returns the character nearest a point. |
| PosFromChar | Returns where a character is drawn. |
Formatting
| Function | Does |
|---|---|
| GetCharFormat | Reads character formatting. |
| SetCharFormat | Sets character formatting. |
| SetFont | Sets the font face and size of all the text. |
| SetFontSize | Makes the selected text larger or smaller. |
| GetParaFormat, SetParaFormat | Reads or sets paragraph formatting. |
| SetBkgndColor | Sets the background colour. |
| InsertTable | Inserts table rows. |
| GetTableParams, SetTableParams | Reads or changes table rows and cells. |
| InsertImage | Replaces the selection with an image. |
| SetTabStops | Sets tab stops. |
| GetBidiOptions, SetBidiOptions | Reads or sets bidirectional options. |
| GetHyphenateInfo, SetHyphenateInfo | Reads or sets hyphenation. |
Editing and undo
| Function | Does |
|---|---|
| CanUndo | Tells whether there is something to undo. |
| Undo | Undoes the last action. |
| CanRedo | Tells whether there is something to redo. |
| Redo | Redoes the next action. |
| GetUndoName | Tells what kind of action the next undo is. |
| GetRedoName | Tells what kind of action the next redo is. |
| EmptyUndoBuffer | Forgets what could be undone. |
| SetUndoLimit | Sets how many actions can be undone. |
| StopGroupTyping | Starts a new undo action for the next typing. |
| CanPaste | Tells whether a clipboard format can be pasted. |
| PasteSpecial | Pastes a given clipboard format. |
| SetReadOnly | Makes the control read-only or editable. |
| GetPasswordChar, SetPasswordChar | Reads or sets the character shown in place of what is typed. |
Options and styles
| Function | Does |
|---|---|
| GetEventMask, SetEventMask | Reads or sets which notifications the control sends. |
| GetOptions, SetOptions | Reads or sets the ECO_* options. |
| GetEditStyle, SetEditStyle | Reads or sets the SES_* edit styles. |
| GetEditStyleEx, SetEditStyleEx | Reads or sets the SES_EX_* edit styles. |
| GetTypographyOptions, SetTypographyOptions | Reads or sets advanced typography. |
| AutoUrlDetect, GetAutoUrlDetect | Turns URL detection on or off, or reads it. |
| GetEllipsisMode, SetEllipsisMode | Reads or sets how text that does not fit is cut. |
| GetEllipsisState | Tells whether an ellipsis is showing. |
| GetTouchOptions, SetTouchOptions | Reads or sets the touch options. |
| GetWordWrapMode, SetWordWrapMode | Reads or sets the word wrap and word break options. |
| GetWordBreakProc, SetWordBreakProc | Reads or replaces the word-break procedure. |
| GetWordBreakProcEx, SetWordBreakProcEx | Reads or replaces the extended word-break procedure. |
| GetAutoCorrectProc, SetAutoCorrectProc | Reads or sets the autocorrect procedure. |
| CallAutocorrectProc | Runs the autocorrect procedure. |
| GetPunctuation, SetPunctuation | Reads or sets the punctuation characters for Asian text. |
| GetPageRotate, SetPageRotate | Reads or sets the text layout. |
| GetStoryType, SetStoryType | Reads or sets a story's type. |
| SetUIAName | Sets the name UI Automation reports. |
| SetPalette | Sets the palette the control draws with. |
| SetOleCallback | Gives the control an IRichEditOleCallback object. |
| GetOleInterface | Returns the control's IRichEditOle interface. |
View and scrolling
| Function | Does |
|---|---|
| GetZoom, SetZoom | Reads or sets the zoom ratio. |
| GetFirstVisibleLine | Returns the top visible line. |
| GetScrollPos, SetScrollPos | Reads or sets the scroll position in pixels. |
| LineScroll | Scrolls by lines. |
| Scroll | Scrolls by a line or a page. |
| ScrollCaret | Scrolls the caret into view. |
| GetThumb | Returns the vertical scroll box position. |
| ShowScrollBar | Shows or hides a scroll bar. |
| GetRect, SetRect, SetRectNP | Reads or sets the formatting rectangle. |
| SetMargins | Sets the left and right margins. |
| SetTargetDevice | Sets the line width or the device text is laid out for. |
| RequestResize | Asks the control for an EN_REQUESTRESIZE notification. |
Streams, files and printing
| Function | Does |
|---|---|
| StreamIn | Replaces the contents with data from a callback. |
| StreamOut | Hands the contents to a callback. |
| LoadRtfFromFile | Loads an RTF file. |
| LoadRtfFromResource | Loads RTF from a resource. |
| LoadRtfFromFileCallback | The stream callback LoadRtfFromFile uses. |
| LoadRtfFromResourceCallback | The stream callback LoadRtfFromResource uses. |
| EnumFontFamProcW | The font enumeration callback SetFont uses. |
| FormatRange | Formats, and draws, text for a device. |
| DisplayBand | Draws text formatted by FormatRange. |
Input method editors
| Function | Does |
|---|---|
| IsIME | Tells whether the input locale is East Asian. |
| GetIMECompMode | Returns the IME composition mode. |
| GetIMECompText | Copies the IME composition text. |
| GetIMEColor, SetIMEColor | Reads or sets the composition colours. |
| GetIMEModeBias, SetIMEModeBias | Reads or sets the IME mode bias. |
| GetIMEOptions, SetIMEOptions | Reads or sets the IME options. |
| GetIMEProperty | Returns a property of the IME. |
| GetLangOptions, SetLangOptions | Reads or sets the IME and Asian language options. |
| GetCTFModeBias, SetCTFModeBias | Reads or sets the Text Services Framework mode bias. |
| GetCTFOpenStatus, SetCTFOpenStatus | Reads, opens or closes the Text Services Framework keyboard. |
| Reconversion | Opens the IME reconversion dialog. |
Types
| Type | Holds |
|---|---|
| RICHEDIT_CUSTOMDATA | A block of RTF in memory, for LoadRtfFromResourceCallback. |
function GetText( byval hRichEdit as HWND ) as ustringReturns all the text of the control as plain text, without formatting. Each paragraph end comes
back as CR LF: text set as "ab" & chr(13) & "cd" reads back as six characters. An empty
control gives "".
It sends WM_GETTEXT rather than calling GetWindowText, so it also reads a control in another
program.
Returns the text.
Example
dim s as ustring = richedit.RichEdit.GetText( hCtrl )
print len( s ); " characters"Microsoft Learn: WM_GETTEXT
function GetTextLength( byval hRichEdit as HWND ) as longReturns the length of the text as GetText returns it, each paragraph end counted as
two characters (CR LF). For the number of character positions use
GetTextLengthEx with GTL_NUMCHARS.
Returns the length in characters.
Example
if richedit.RichEdit.GetTextLength( hCtrl ) = 0 then print "empty"Microsoft Learn: WM_GETTEXTLENGTH
function SetText( byval hRichEdit as HWND, byval pwszText as wstring ptr ) as longReplaces all the text with pwszText, as plain text, and empties the undo queue: CanUndo
returns 0 afterwards. To set RTF, use SetTextExW or
StreamIn.
| Parameter | Meaning |
|---|---|
hRichEdit |
The rich edit control. |
pwszText |
The new text: a literal, a ustring or a wstring. |
Returns nonzero on success, 0 on failure.
Example
richedit.RichEdit.SetText( hCtrl, "First paragraph" & chr(13) & "Second paragraph" )Microsoft Learn: WM_SETTEXT
function GetTextEx( byval hRichEdit as HWND, byval lpgtex as ..GETTEXTEX ptr, byval buffer as any ptr ) as DWORDCopies the text, or the selection, into buffer. GETTEXTEX says how: cb is the buffer size
in bytes, flags picks GT_DEFAULT, GT_USECRLF, GT_SELECTION …, and codepage the code
page (1200 for UTF-16). With GT_DEFAULT paragraph ends stay single carriage returns.
| Parameter | Meaning |
|---|---|
lpgtex |
A filled-in GETTEXTEX. |
buffer |
Receives the text and a terminating null. |
Returns the number of characters (or bytes, for a narrow code page) copied.
Example
dim gt as GETTEXTEX
dim buf as wstring * 256
gt.cb = sizeof( buf ) : gt.flags = GT_DEFAULT : gt.codepage = 1200
richedit.RichEdit.GetTextEx( hCtrl, @gt, @buf )Microsoft Learn: EM_GETTEXTEX
function GetTextLengthEx( byval hRichEdit as HWND, byval lpgtex as ..GETTEXTLENGTHEX ptr ) as longMeasures the text the way GETTEXTLENGTHEX asks: flags combines GTL_NUMCHARS or
GTL_NUMBYTES with GTL_USECRLF (count each paragraph end as two) and GTL_PRECISE or
GTL_CLOSE; codepage is the code page the count is for. For "one" & chr(13) & "two",
GTL_NUMCHARS gives 7 and GTL_NUMCHARS or GTL_USECRLF gives 8.
Returns the length, or E_INVALIDARG.
Example
dim gtl as GETTEXTLENGTHEX
gtl.flags = GTL_NUMCHARS : gtl.codepage = 1200
print richedit.RichEdit.GetTextLengthEx( hCtrl, @gtl ); " character positions"Microsoft Learn: EM_GETTEXTLENGTHEX
function SetTextExW( byval hRichEdit as HWND, byval pstex as SETTEXTEX ptr, byval pwszText as wstring ptr ) as DWORDReplaces the text, or with ST_SELECTION only the selection, with pwszText. Text that starts
with {\rtf is read as RTF, anything else as plain text. SETTEXTEX.flags combines
ST_DEFAULT, ST_KEEPUNDO, ST_SELECTION, ST_NEWCHARS and ST_UNICODE; codepage is the
code page of the text: 1200 for a wstring, or CP_ACP for RTF held in a narrow string,
passed with a cast.
| Parameter | Meaning |
|---|---|
pstex |
A filled-in SETTEXTEX. |
pwszText |
The text or RTF. |
Returns 1 on success (for ST_SELECTION, the number of characters inserted), 0 on failure.
Example
dim stx as SETTEXTEX
stx.flags = ST_DEFAULT : stx.codepage = CP_ACP
dim rtf as string = "{\rtf1\ansi plain {\b bold} plain}"
richedit.RichEdit.SetTextExW( hCtrl, @stx, cast( wstring ptr, strptr( rtf ) ) )Microsoft Learn: EM_SETTEXTEX
function GetTextRange( byval hRichEdit as HWND, byval lptrg as TEXTRANGEW ptr ) as DWORDCopies the characters from chrg.cpMin to just before chrg.cpMax of a TEXTRANGEW into the
buffer its lpstrText points to, which must have room for them and a terminating null.
Returns the number of characters copied.
Example
dim buf as wstring * 32
dim tr as TEXTRANGEW
tr.chrg.cpMin = 4 : tr.chrg.cpMax = 7 : tr.lpstrText = @buf
richedit.RichEdit.GetTextRange( hCtrl, @tr ) ' buf holds characters 4, 5 and 6Microsoft Learn: EM_GETTEXTRANGE
function GetLine( byval hRichEdit as HWND, byval which as DWORD ) as ustringReturns line which (counted from 0) as plain text. A line that ends a paragraph comes back with
its carriage return (13) at the end, and so does the last line: for "one" & chr(13) & "two"
both lines read back as four characters. A line number past the last line gives "".
The line is read into a buffer of about 32,000 characters; longer lines are not supported.
Returns the line.
Example
dim s as ustring = richedit.RichEdit.GetLine( hCtrl, 0 )
print "first line: "; rtrim( s, chr(13) )Microsoft Learn: EM_GETLINE
function GetLineCount( byval hRichEdit as HWND ) as longReturns the number of lines, as displayed. An empty control has one line.
Returns the line count.
Example
print richedit.RichEdit.GetLineCount( hCtrl ); " lines"Microsoft Learn: EM_GETLINECOUNT
function LineIndex( byval hRichEdit as HWND, byval nLine as long ) as longReturns the position of the first character of line nLine; -1 means the line that holds the
caret. In "first line" & chr(13) & "second" line 1 starts at 11.
Returns the position, or -1 when the line does not exist.
Example
dim nStart as long = richedit.RichEdit.LineIndex( hCtrl, 1 )
richedit.RichEdit.SetSel( hCtrl, nStart, nStart ) ' caret to the start of line 1Microsoft Learn: EM_LINEINDEX
function LineFromChar( byval hRichEdit as HWND, byval index as DWORD ) as longReturns the line that holds the character at index. -1 gives the line of the caret, or of
the start of the selection. Positions beyond 65,535 need ExLineFromChar.
Returns the line, counted from 0.
Example
print "the caret is on line"; richedit.RichEdit.LineFromChar( hCtrl, -1 ) + 1Microsoft Learn: EM_LINEFROMCHAR
function ExLineFromChar( byval hRichEdit as HWND, byval iIndex as long ) as longReturns the line that holds the character at iIndex, for any position in the text.
Returns the line, counted from 0.
Example
dim cr as CHARRANGE
richedit.RichEdit.ExGetSel( hCtrl, @cr )
print "line"; richedit.RichEdit.ExLineFromChar( hCtrl, cr.cpMin ) + 1Microsoft Learn: EM_EXLINEFROMCHAR
function LineLength( byval hRichEdit as HWND, byval index as DWORD ) as longReturns the length of the line that holds the character at index, without its carriage return.
With -1 it returns the number of characters on the selected lines that are not selected.
Returns the length in characters.
Example
dim nLen as long = richedit.RichEdit.LineLength( hCtrl, richedit.RichEdit.LineIndex( hCtrl, 0 ) )Microsoft Learn: EM_LINELENGTH
function GetLimitText( byval hRichEdit as HWND ) as long
sub LimitText( byval hRichEdit as HWND, byval chMax as DWORD )
sub SetLimitText( byval hRichEdit as HWND, byval chMax as DWORD )GetLimitText returns how many characters the user can type or paste; a new control allows
32,767. LimitText and SetLimitText are the same call: they set that limit to chMax, and 0
sets 65,536. The limit does not stop text set by the program: SetText with ten
characters still sets all ten under a limit of 5. For a limit above 65,536 use
ExLimitText.
Returns (GetLimitText) the limit in characters.
Example
richedit.RichEdit.LimitText( hCtrl, 500 )
print richedit.RichEdit.GetLimitText( hCtrl ) ' 500Microsoft Learn: EM_GETLIMITTEXT, EM_LIMITTEXT
sub ExLimitText( byval hRichEdit as HWND, byval dwLimit as DWORD )Sets how many characters the user can type or paste, with no 64K ceiling. 0 sets the default of 65,536.
Example
richedit.RichEdit.ExLimitText( hCtrl, 1000000 )Microsoft Learn: EM_EXLIMITTEXT
function GetTextMode( byval hRichEdit as HWND ) as DWORD
function SetTextMode( byval hRichEdit as HWND, byval pvalues as long ) as longGetTextMode returns the control's text mode: TM_RICHTEXT or TM_PLAINTEXT, combined with
TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO and TM_SINGLECODEPAGE or TM_MULTICODEPAGE. A new
RichEdit50W control reads 42 (TM_RICHTEXT or TM_MULTILEVELUNDO or TM_MULTICODEPAGE).
Returns (GetTextMode) the TM_* flags; (SetTextMode) 0.
Example
print richedit.RichEdit.GetTextMode( hCtrl )
SendMessageW( hCtrl, EM_SETTEXTMODE, TM_PLAINTEXT, 0 ) ' what changes the mode of an empty controlMicrosoft Learn: EM_GETTEXTMODE, EM_SETTEXTMODE
function GetModify( byval hRichEdit as HWND ) as long
sub SetModify( byval hRichEdit as HWND, byval fModify as long )The control sets its modification flag whenever the text changes. GetModify reads it;
SetModify sets it (nonzero) or clears it (0), for example after saving.
Returns (GetModify) nonzero when the text has changed since the flag was cleared.
Example
if richedit.RichEdit.GetModify( hCtrl ) then print "unsaved changes"
richedit.RichEdit.SetModify( hCtrl, 0 )Microsoft Learn: EM_GETMODIFY, EM_SETMODIFY
function GetSel( byval hRichEdit as HWND, byval pdwStartPos as DWORD ptr, byval pdwEndPos as DWORD ptr ) as longReads the start and end of the selection into the two variables; either pointer may be NULL.
When nothing is selected both hold the caret position.
Returns the start in the low word and the end in the high word, which is only meaningful for
positions below 65,536 (a selection from 7 to 11 returns &hB0007); use the variables, or
ExGetSel, instead.
Example
dim as DWORD nStart, nEnd
richedit.RichEdit.GetSel( hCtrl, @nStart, @nEnd )
print "selected"; nStart; " to"; nEndMicrosoft Learn: EM_GETSEL
sub SetSel( byval hRichEdit as HWND, byval nStart as long, byval nEnd as long )Selects the characters from nStart to just before nEnd. 0, -1 selects all the text; a
start of -1 removes the selection and leaves the caret where it was; equal values put the caret
there with nothing selected.
| Parameter | Meaning |
|---|---|
nStart |
Where the selection starts. |
nEnd |
Where it ends; -1 for the end of the text. |
Example
richedit.RichEdit.SetSel( hCtrl, 0, -1 ) ' select allMicrosoft Learn: EM_SETSEL
sub ExGetSel( byval hRichEdit as HWND, byval lpchr as CHARRANGE ptr )Reads the selection into a CHARRANGE: cpMin is the start, cpMax the end.
Example
dim cr as CHARRANGE
richedit.RichEdit.ExGetSel( hCtrl, @cr )
print cr.cpMax - cr.cpMin; " characters selected"Microsoft Learn: EM_EXGETSEL
function ExSetSel( byval hRichEdit as HWND, byval lpcr as CHARRANGE ptr ) as DWORDSelects the range a CHARRANGE holds, with the same conventions as SetSel.
Returns the end of the selection the control actually set (5 for 0 to 5).
Example
dim cr as CHARRANGE
cr.cpMin = 0 : cr.cpMax = 5
richedit.RichEdit.ExSetSel( hCtrl, @cr )Microsoft Learn: EM_EXSETSEL
function GetSelText( byval hRichEdit as HWND ) as ustringReturns the selected text as plain text, or "" when nothing is selected.
Returns the selected text.
Example
richedit.RichEdit.SetSel( hCtrl, 0, 5 )
print richedit.RichEdit.GetSelText( hCtrl ) ' the first five charactersMicrosoft Learn: EM_GETSELTEXT
sub ReplaceSel( byval hRichEdit as HWND, byval bCanBeUndone as long, byval pwszText as wstring ptr )Replaces the selection with pwszText, in the format of the selection's start; with nothing
selected it inserts the text at the caret. To append, put the caret at the end of the text first,
as the example does.
| Parameter | Meaning |
|---|---|
bCanBeUndone |
Nonzero to make the replacement an action Undo can undo. |
pwszText |
The new text. |
Example
dim n as long = richedit.RichEdit.GetTextLength( hCtrl )
richedit.RichEdit.SetSel( hCtrl, n, n )
richedit.RichEdit.ReplaceSel( hCtrl, true, "appended" )Microsoft Learn: EM_REPLACESEL
function SelectionType( byval hRichEdit as HWND ) as longTells what the selection holds, as SEL_* flags: SEL_EMPTY (0), or a combination of
SEL_TEXT, SEL_OBJECT, SEL_MULTICHAR and SEL_MULTIOBJECT. Four selected characters give
5 (SEL_TEXT or SEL_MULTICHAR).
Returns the flags.
Example
if richedit.RichEdit.SelectionType( hCtrl ) and SEL_OBJECT then print "an object is selected"Microsoft Learn: EM_SELECTIONTYPE
sub HideSelection( byval hRichEdit as HWND, byval fHide as DWORD )Hides the selection highlight (fHide nonzero) or shows it again (0). The selection itself does
not change.
Example
richedit.RichEdit.HideSelection( hCtrl, true )Microsoft Learn: EM_HIDESELECTION
function FindText( byval hRichEdit as HWND, byval fOptions as DWORD, byval lpft as FINDTEXTW ptr ) as longSearches for lpstrText of a FINDTEXTW within its range chrg. fOptions combines FR_DOWN
(search forward; without it the search runs backward), FR_MATCHCASE and FR_WHOLEWORD. The
selection does not move.
Returns the position where the text was found, or -1.
Example
dim ft as FINDTEXTW
ft.chrg.cpMin = 0 : ft.chrg.cpMax = -1
ft.lpstrText = @wstr( "two" )
print "found at"; richedit.RichEdit.FindText( hCtrl, FR_DOWN, @ft )Microsoft Learn: EM_FINDTEXTW
function FindTextEx( byval hRichEdit as HWND, byval fOptions as DWORD, byval lpftexw as FINDTEXTEXW ptr ) as longSearches like FindText and also stores the range of the text found in the
structure's chrgText, ready to pass to ExSetSel. In "one two three two", a
search for "two" from 0 returns 4 with chrgText 4 to 7.
Returns the position where the text was found, or -1.
Example
dim ft as FINDTEXTEXW
ft.chrg.cpMin = 0 : ft.chrg.cpMax = -1
ft.lpstrText = @wstr( "two" )
if richedit.RichEdit.FindTextEx( hCtrl, FR_DOWN, @ft ) >= 0 then richedit.RichEdit.ExSetSel( hCtrl, @ft.chrgText )Microsoft Learn: EM_FINDTEXTEXW
function FindWordBreak( byval hRichEdit as HWND, byval fOperation as DWORD, byval dwStartPos as DWORD ) as DWORDFinds a word break from dwStartPos, or tells something about the character there, depending on
fOperation: WB_MOVEWORDRIGHT and WB_MOVEWORDLEFT return where the next or previous word
starts, WB_LEFT and WB_RIGHT where the word ends, and WB_ISDELIMITER whether the
character is a delimiter. In "one two three two", WB_MOVEWORDRIGHT from 0 returns 4.
Returns the position found, or for the classifying operations the answer.
Example
dim nNext as DWORD = richedit.RichEdit.FindWordBreak( hCtrl, WB_MOVEWORDRIGHT, 0 )Microsoft Learn: EM_FINDWORDBREAK
function CharFromPos( byval hRichEdit as HWND, byval lppl as POINTL ptr ) as longReturns the character nearest a point given in client coordinates. With the point that PosFromChar gives for a character, it returns that character.
Returns the position of the character.
Example
dim pt as POINTL
pt.x = 10 : pt.y = 10
print "character"; richedit.RichEdit.CharFromPos( hCtrl, @pt )Microsoft Learn: EM_CHARFROMPOS
sub PosFromChar( byval hRichEdit as HWND, byval pt as POINTL ptr, byval index as DWORD )Stores in pt the client coordinates of the top-left corner of the character at index.
Example
dim pt as POINTL
richedit.RichEdit.PosFromChar( hCtrl, @pt, 3 )
print "character 3 is at"; pt.x; ","; pt.yMicrosoft Learn: EM_POSFROMCHAR
function GetCharFormat( byval hRichEdit as HWND, byval fOption as DWORD, byval lpcf as CHARFORMATW ptr ) as DWORDReads character formatting into a CHARFORMATW (or a CHARFORMAT2W, cast): with SCF_SELECTION
the formatting of the selection, with SCF_DEFAULT the default formatting. Set cbSize first.
Sizes (yHeight) are in twips, twentieths of a point.
| Parameter | Meaning |
|---|---|
fOption |
SCF_SELECTION or SCF_DEFAULT. |
lpcf |
Receives the formatting. |
Returns the dwMask of the attributes that are the same over the whole selection; the same
value is stored in dwMask.
Example
dim cf as CHARFORMATW
cf.cbSize = sizeof( cf )
richedit.RichEdit.GetCharFormat( hCtrl, SCF_SELECTION, @cf )
print cf.szFaceName; cf.yHeight / 20; " pt"Microsoft Learn: EM_GETCHARFORMAT
function SetCharFormat( byval hRichEdit as HWND, byval chfmt as DWORD, byval lpcf as CHARFORMATW ptr ) as longApplies the attributes dwMask names from a CHARFORMATW (or a CHARFORMAT2W, cast). chfmt
says to what: SCF_SELECTION (the selection, or the typing at the caret), SCF_WORD or SCF_SELECTION (the word at the caret), SCF_ALL (all the text) or SCF_DEFAULT (the default
formatting).
Returns nonzero on success, 0 on failure.
Example
dim cf as CHARFORMATW
cf.cbSize = sizeof( cf ) : cf.dwMask = CFM_BOLD : cf.dwEffects = CFE_BOLD
richedit.RichEdit.SetSel( hCtrl, 0, 5 )
richedit.RichEdit.SetCharFormat( hCtrl, SCF_SELECTION, @cf )Microsoft Learn: EM_SETCHARFORMAT
function SetFont( byval hRichEdit as HWND, byref wszFaceName as wstring, byval ptsize as long ) as LRESULTSets the face and size of all the text. It looks up the font's character set and pitch by
enumerating the fonts called wszFaceName, then applies face, character set and size to the
whole text with one SCF_ALL call.
| Parameter | Meaning |
|---|---|
wszFaceName |
The font's face name, such as "Segoe UI". |
ptsize |
The size in points. |
Returns 0 when the formatting failed. If the operation succeeds, the return value is a nonzero value.
Example
richedit.RichEdit.SetFont( hCtrl, "Consolas", 10 )Microsoft Learn: EM_SETCHARFORMAT, EnumFontFamiliesW
function SetFontSize( byval hRichEdit as HWND, byval ptsize as long ) as longMakes the font of the selected text larger (ptsize positive) or smaller (negative) by that many
points: 12-point text with 2 becomes 14 points. The control rounds to its standard sizes and
keeps the size between 1 and 1638 points.
Returns nonzero on success, 0 when there was no change.
Example
richedit.RichEdit.SetSel( hCtrl, 0, -1 )
richedit.RichEdit.SetFontSize( hCtrl, 2 )Microsoft Learn: EM_SETFONTSIZE
function GetParaFormat( byval hRichEdit as HWND, byval pParaFmt as PARAFORMAT ptr ) as DWORD
function SetParaFormat( byval hRichEdit as HWND, byval pfmt as PARAFORMAT ptr ) as longRead or set the paragraph formatting of the paragraphs in the selection: alignment, indents, tab
stops, numbering and, with a PARAFORMAT2 (cast), spacing, borders and shading. Set cbSize
first and, to set, name the attributes in dwMask.
Returns (GetParaFormat) the dwMask of the attributes that are the same over the
selection; (SetParaFormat) nonzero on success.
Example
dim pf as PARAFORMAT2
pf.cbSize = sizeof( pf ) : pf.dwMask = PFM_ALIGNMENT : pf.wAlignment = PFA_CENTER
richedit.RichEdit.SetParaFormat( hCtrl, cast( PARAFORMAT ptr, @pf ) )Microsoft Learn: EM_GETPARAFORMAT, EM_SETPARAFORMAT
function SetBkgndColor( byval hRichEdit as HWND, byval pSysColor as DWORD, byval pBkColor as DWORD ) as DWORDSets the background colour. With pSysColor nonzero the control uses the system window colour
and ignores pBkColor; with 0 it uses the COLORREF in pBkColor.
Returns the previous background colour.
Example
richedit.RichEdit.SetBkgndColor( hCtrl, 0, BGR( 255, 255, 224 ) ) ' light yellowMicrosoft Learn: EM_SETBKGNDCOLOR
function InsertTable( byval hRichEdit as HWND, byval lptp as TABLEROWPARMS ptr, byval lptcp as TABLECELLPARMS ptr ) as DWORDInserts cRow identical rows of cCell empty cells at the selection. lptp describes the rows
(set cbRow and cbCell to the two structure sizes); lptcp points to an array of cCell
TABLECELLPARMS, one per cell, with widths in twips.
Returns S_OK on success, otherwise an error code.
Example
dim trp as TABLEROWPARMS
trp.cbRow = sizeof( TABLEROWPARMS ) : trp.cbCell = sizeof( TABLECELLPARMS ) : trp.cCell = 3 : trp.cRow = 2
dim tcp( 0 to 2 ) as TABLECELLPARMS
for i as long = 0 to 2 : tcp( i ).dxWidth = 1440 : next ' one inch each
richedit.RichEdit.InsertTable( hCtrl, @trp, @tcp( 0 ) )Microsoft Learn: EM_INSERTTABLE
function GetTableParams( byval hRichEdit as HWND, byval lptp as TABLEROWPARMS ptr, byval lptcp as TABLECELLPARMS ptr ) as DWORD
function SetTableParams( byval hRichEdit as HWND, byval lptp as TABLEROWPARMS ptr, byval lptcp as TABLECELLPARMS ptr ) as DWORDRead or change the row and cell parameters of the table row that holds the selection. Set
cbRow, cbCell and cCell first; lptcp points to an array with room for cCell cells.
Returns S_OK on success, otherwise an error code.
Example
dim trp as TABLEROWPARMS
trp.cbRow = sizeof( TABLEROWPARMS ) : trp.cbCell = sizeof( TABLECELLPARMS ) : trp.cCell = 3
dim tcp( 0 to 2 ) as TABLECELLPARMS
if richedit.RichEdit.GetTableParams( hCtrl, @trp, @tcp( 0 ) ) = S_OK then print "first cell"; tcp( 0 ).dxWidth; " twips"Microsoft Learn: EM_GETTABLEPARMS, EM_SETTABLEPARMS
function InsertImage( byval hRichEdit as HWND, byval lpip as RICHEDIT_IMAGE_PARAMETERS ptr ) as DWORDReplaces the selection with an image read from the IStream in pIStream. xWidth and
yHeight give its size in HIMETRIC units (hundredths of a millimetre), Type its vertical
alignment (TA_BASELINE, TA_TOP, TA_BOTTOM), and pwszAlternateText its alternative text.
Returns S_OK on success, otherwise an error code.
Example
dim pStream as IStream ptr
SHCreateStreamOnFileEx( "picture.png", STGM_READ, 0, false, NULL, @pStream )
dim ip as RICHEDIT_IMAGE_PARAMETERS
ip.xWidth = 2540 : ip.yHeight = 2540 : ip.Type = TA_BASELINE : ip.pwszAlternateText = @wstr( "a picture" ) : ip.pIStream = pStream
if pStream then richedit.RichEdit.InsertImage( hCtrl, @ip ) : pStream->lpVtbl->Release( pStream )Microsoft Learn: EM_INSERTIMAGE
function SetTabStops( byval hRichEdit as HWND, byval nTabs as long, byval rgTabStops as LONG_PTR ) as longSets tab stops for the whole control. rgTabStops is the address of an array of nTabs long
positions in dialog template units; 0 tabs restores the default of a stop every 32 units.
Per-paragraph tab stops are set with SetParaFormat.
Returns nonzero when all the tabs were set.
Example
dim tabs( 0 to 1 ) as long = { 32, 64 }
richedit.RichEdit.SetTabStops( hCtrl, 2, cast( LONG_PTR, @tabs( 0 ) ) )Microsoft Learn: EM_SETTABSTOPS
sub GetBidiOptions( byval hRichEdit as HWND, byval lpbo as BIDIOPTIONS ptr )
sub SetBidiOptions( byval hRichEdit as HWND, byval pOptions as BIDIOPTIONS ptr )Read or set the options for right-to-left text in a BIDIOPTIONS: wMask names the BOM_*
options to read or change, wEffects holds their BOE_* values. Set cbSize first.
Example
dim bo as BIDIOPTIONS
bo.cbSize = sizeof( bo ) : bo.wMask = BOM_CONTEXTREADING : bo.wEffects = BOE_CONTEXTREADING
richedit.RichEdit.SetBidiOptions( hCtrl, @bo )Microsoft Learn: EM_GETBIDIOPTIONS, EM_SETBIDIOPTIONS
sub GetHyphenateInfo( byval hRichEdit as HWND, byval lphi as HYPHENATEINFO ptr )
sub SetHyphenateInfo( byval hRichEdit as HWND, byval phinfo as HYPHENATEINFO ptr )Read or set how the control hyphenates, in a HYPHENATEINFO: the hyphenation zone
dxHyphenateZone and the procedure pfnHyphenate that decides where words break. Set cbSize
first.
Example
dim hi as HYPHENATEINFO
hi.cbSize = sizeof( hi )
richedit.RichEdit.GetHyphenateInfo( hCtrl, @hi )Microsoft Learn: EM_GETHYPHENATEINFO, EM_SETHYPHENATEINFO
function CanUndo( byval hRichEdit as HWND ) as longTells whether there is an action to undo.
Returns nonzero when Undo would do something.
Example
if richedit.RichEdit.CanUndo( hCtrl ) then print "something to undo"Microsoft Learn: EM_CANUNDO
function Undo( byval hRichEdit as HWND ) as longUndoes the last action in the undo queue. With multilevel undo, the default, each call goes one action further back.
Returns nonzero on success, 0 when there was nothing to undo.
Example
if richedit.RichEdit.CanUndo( hCtrl ) then richedit.RichEdit.Undo( hCtrl )Microsoft Learn: EM_UNDO
function CanRedo( byval hRichEdit as HWND ) as longTells whether there is an undone action to redo.
Returns nonzero when Redo would do something.
Example
if richedit.RichEdit.CanRedo( hCtrl ) then print "redo is possible"Microsoft Learn: EM_CANREDO
function Redo( byval hRichEdit as HWND ) as longRedoes the action that Undo last undid.
Returns nonzero on success, 0 when there was nothing to redo.
Example
richedit.RichEdit.Redo( hCtrl )Microsoft Learn: EM_REDO
function GetUndoName( byval hRichEdit as HWND ) as DWORDTells what kind of action the next Undo would undo, as a UID_* value: UID_TYPING,
UID_DELETE, UID_DRAGDROP, UID_CUT, UID_PASTE … or UID_UNKNOWN (0). A control with
nothing to undo returns 0.
Returns the UID_* value.
Example
if richedit.RichEdit.GetUndoName( hCtrl ) = UID_TYPING then print "undo typing"Microsoft Learn: EM_GETUNDONAME
function GetRedoName( byval hRichEdit as HWND ) as longTells what kind of action the next Redo would redo, as a UID_* value.
Returns the UID_* value, 0 when there is nothing to redo or the kind is not known.
Example
if richedit.RichEdit.GetRedoName( hCtrl ) = UID_PASTE then print "redo paste"Microsoft Learn: EM_GETREDONAME
sub EmptyUndoBuffer( byval hRichEdit as HWND )Empties the undo and redo queues, so that nothing done so far can be undone; CanUndo returns 0 afterwards.
Example
richedit.RichEdit.EmptyUndoBuffer( hCtrl )Microsoft Learn: EM_EMPTYUNDOBUFFER
function SetUndoLimit( byval hRichEdit as HWND, byval maxactions as DWORD ) as DWORDSets how many actions the undo queue keeps; the default is 100, and 0 turns undo off.
Returns the new limit, which can be lower than asked for when memory is short.
Example
richedit.RichEdit.SetUndoLimit( hCtrl, 50 )Microsoft Learn: EM_SETUNDOLIMIT
function StopGroupTyping( byval hRichEdit as HWND ) as DWORDEnds the current undo action for typing, so that what is typed next is undone separately. The control otherwise groups consecutive typing into one action.
Returns 0.
Example
richedit.RichEdit.StopGroupTyping( hCtrl )Microsoft Learn: EM_STOPGROUPTYPING
function CanPaste( byval hRichEdit as HWND, byval clipformat as long ) as longTells whether the control can paste clipboard format clipformat; 0 asks about any format on the
clipboard.
Returns nonzero when it can.
Example
if richedit.RichEdit.CanPaste( hCtrl, CF_UNICODETEXT ) then print "text can be pasted"Microsoft Learn: EM_CANPASTE
sub PasteSpecial( byval hRichEdit as HWND, byval clpfmt as DWORD, byval lprps as REPASTESPECIAL ptr )Pastes the clipboard's data in format clpfmt, for example CF_UNICODETEXT to paste formatted
text as plain text. lprps may be NULL, or a REPASTESPECIAL that says how to show a pasted
object.
Example
richedit.RichEdit.PasteSpecial( hCtrl, CF_UNICODETEXT, NULL ) ' paste as plain textMicrosoft Learn: EM_PASTESPECIAL
function SetReadOnly( byval hRichEdit as HWND, byval fReadOnly as long ) as longMakes the control read-only (nonzero) or editable again (0). The program can still change the
text with SetText and ReplaceSel; the ECO_READONLY bit of GetOptions shows the state.
Returns nonzero on success.
Example
richedit.RichEdit.SetReadOnly( hCtrl, true )Microsoft Learn: EM_SETREADONLY
function GetPasswordChar( byval hRichEdit as HWND ) as long
sub SetPasswordChar( byval hRichEdit as HWND, byval dwchar as DWORD )SetPasswordChar makes the control show dwchar in place of every character, or show the text
again with 0. GetPasswordChar returns the character in use.
Returns (GetPasswordChar) the character code, 0 when there is none.
Example
richedit.RichEdit.SetPasswordChar( hCtrl, asc( "*" ) )
print richedit.RichEdit.GetPasswordChar( hCtrl ) ' 42Microsoft Learn: EM_GETPASSWORDCHAR, EM_SETPASSWORDCHAR
function GetEventMask( byval hRichEdit as HWND ) as DWORD
function SetEventMask( byval hRichEdit as HWND, byval fMask as long ) as longThe event mask says which notifications the control sends its parent: ENM_CHANGE,
ENM_SELCHANGE, ENM_LINK, ENM_REQUESTRESIZE, ENM_SCROLL, ENM_KEYEVENTS,
ENM_MOUSEEVENTS … combined with or. A new control has an empty mask. SetEventMask replaces
the whole mask; to add one, or it with GetEventMask.
Returns (GetEventMask) the mask; (SetEventMask) the previous mask.
Example
richedit.RichEdit.SetEventMask( hCtrl, richedit.RichEdit.GetEventMask( hCtrl ) or ENM_SELCHANGE )Microsoft Learn: EM_GETEVENTMASK, EM_SETEVENTMASK
function GetOptions( byval hRichEdit as HWND ) as DWORD
function SetOptions( byval hRichEdit as HWND, byval fCoop as long, byval fOptions as long ) as longRead or change the ECO_* options: ECO_AUTOVSCROLL, ECO_AUTOHSCROLL, ECO_NOHIDESEL,
ECO_READONLY, ECO_WANTRETURN, ECO_SAVESEL, ECO_SELECTIONBAR (a margin at the left for
selecting lines) … fCoop says how fOptions combines with the current options: ECOOP_SET,
ECOOP_OR, ECOOP_AND or ECOOP_XOR.
Returns (GetOptions) the options; (SetOptions) the options after the change.
Example
richedit.RichEdit.SetOptions( hCtrl, ECOOP_OR, ECO_SELECTIONBAR )Microsoft Learn: EM_GETOPTIONS, EM_SETOPTIONS
function GetEditStyle( byval hRichEdit as HWND ) as DWORD
function SetEditStyle( byval hRichEdit as HWND, byval fStyle as long, byval fMask as long ) as DWORDRead or change the SES_* edit styles (SES_EMULATESYSEDIT, SES_BEEPONMAXTEXT,
SES_XLTCRCRLFTOCR, SES_HYPERLINKTOOLTIPS …). SetEditStyle changes the styles named in
fMask to their values in fStyle.
Returns the edit styles (for SetEditStyle, as they are after the change).
Example
richedit.RichEdit.SetEditStyle( hCtrl, SES_HYPERLINKTOOLTIPS, SES_HYPERLINKTOOLTIPS )Microsoft Learn: EM_GETEDITSTYLE, EM_SETEDITSTYLE
function GetEditStyleEx( byval hRichEdit as HWND ) as DWORD
function SetEditStyleEx( byval hRichEdit as HWND, byval fStyle as long, byval fMask as long ) as DWORDRead or change the extended edit styles SES_EX_* (SES_EX_NOTABLE, SES_EX_HANDLEFRIENDLYURL,
SES_EX_MULTITOUCH …), the styles in fMask taking their values from fStyle.
Returns the extended edit styles.
Example
richedit.RichEdit.SetEditStyleEx( hCtrl, SES_EX_HANDLEFRIENDLYURL, SES_EX_HANDLEFRIENDLYURL )Microsoft Learn: EM_GETEDITSTYLEEX, EM_SETEDITSTYLEEX
function GetTypographyOptions( byval hRichEdit as HWND ) as DWORD
function SetTypographyOptions( byval hRichEdit as HWND, byval pto as long, byval fMask as long ) as longRead or change the typography options: TO_ADVANCEDTYPOGRAPHY (line breaking and layout for
complex scripts), TO_SIMPLELINEBREAK and others. SetTypographyOptions sets the options in
fMask to their values in pto.
Returns (GetTypographyOptions) the options; (SetTypographyOptions) nonzero on success.
Example
richedit.RichEdit.SetTypographyOptions( hCtrl, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY )Microsoft Learn: EM_GETTYPOGRAPHYOPTIONS, EM_SETTYPOGRAPHYOPTIONS
function AutoUrlDetect( byval hRichEdit as HWND, byval fUrlDetect as long ) as long
function GetAutoUrlDetect( byval hRichEdit as HWND ) as longAutoUrlDetect turns detection of URLs in the text on or off: 0 turns it off, AURL_ENABLEURL
turns it on, and AURL_ENABLEEMAILADDR, AURL_ENABLETELNO, AURL_ENABLEEAURLS and
AURL_ENABLEDRIVELETTERS add other kinds of link. Detected links are shown as links; to be told
when one is clicked, add ENM_LINK to the event mask. GetAutoUrlDetect reads the setting.
Returns (AutoUrlDetect) 0 on success, otherwise an error code; (GetAutoUrlDetect) the
AURL_* flags in force, 0 when detection is off.
Example
richedit.RichEdit.AutoUrlDetect( hCtrl, AURL_ENABLEURL )
print richedit.RichEdit.GetAutoUrlDetect( hCtrl ) ' 1Microsoft Learn: EM_AUTOURLDETECT, EM_GETAUTOURLDETECT
function GetEllipsisMode( byval hRichEdit as HWND, byval pmode as DWORD ptr ) as DWORD
function SetEllipsisMode( byval hRichEdit as HWND, byval fMode as DWORD ) as DWORDThe ellipsis mode says how text that does not fit is cut: ELLIPSIS_NONE, ELLIPSIS_END (at
any character) or ELLIPSIS_WORD (at a word). GetEllipsisMode stores it in *pmode;
SetEllipsisMode sets it.
Returns nonzero on success.
Example
dim nMode as DWORD
richedit.RichEdit.SetEllipsisMode( hCtrl, ELLIPSIS_END )
richedit.RichEdit.GetEllipsisMode( hCtrl, @nMode ) ' nMode is ELLIPSIS_ENDMicrosoft Learn: EM_GETELLIPSISMODE, EM_SETELLIPSISMODE
function GetEllipsisState( byval hRichEdit as HWND ) as DWORDTells whether the control is showing an ellipsis now, because text was cut under the ellipsis mode.
Returns nonzero when an ellipsis is showing.
Example
if richedit.RichEdit.GetEllipsisState( hCtrl ) then print "the text is cut"Microsoft Learn: EM_GETELLIPSISSTATE
function GetTouchOptions( byval hRichEdit as HWND, byval Options as long ptr ) as DWORD
sub SetTouchOptions( byval hRichEdit as HWND, byval Options as long, byval fEnable as long )Read or set a touch option: RTO_SHOWHANDLES (show the touch gripper handles) or
RTO_DISABLEHANDLES. SetTouchOptions turns Options on (fEnable nonzero) or off.
GetTouchOptions sends Options as the option value itself, though it is declared long ptr:
pass the option cast, cast( long ptr, RTO_SHOWHANDLES ), not the address of a variable.
Returns (GetTouchOptions) the state of that option.
Example
richedit.RichEdit.SetTouchOptions( hCtrl, RTO_SHOWHANDLES, true )
print richedit.RichEdit.GetTouchOptions( hCtrl, cast( long ptr, RTO_SHOWHANDLES ) )Microsoft Learn: EM_GETTOUCHOPTIONS, EM_SETTOUCHOPTIONS
function GetWordWrapMode( byval hRichEdit as HWND ) as DWORD
function SetWordWrapMode( byval hRichEdit as HWND, byval pvalues as long ) as longRead or set the word-wrap and word-break options for Asian text, as WBF_* flags
(WBF_WORDWRAP, WBF_WORDBREAK, WBF_OVERFLOW …). Current rich edit controls report and keep 0
here; whether lines wrap at all is set with SetTargetDevice.
Returns (GetWordWrapMode) the flags; (SetWordWrapMode) the previous flags.
Example
dim nWrap as DWORD = richedit.RichEdit.GetWordWrapMode( hCtrl )Microsoft Learn: EM_GETWORDWRAPMODE, EM_SETWORDWRAPMODE
function GetWordBreakProc( byval hRichEdit as HWND ) as LONG_PTR
sub SetWordBreakProc( byval hRichEdit as HWND, byval pfn as LONG_PTR )Read or replace the procedure that decides where words break, for word wrap and for moving by
words. The procedure has the EDITWORDBREAKPROCW shape: it gets the text, a position, the length
and a WB_* code, and returns a position or a flag. SetWordBreakProc with 0 restores the
control's own; GetWordBreakProc returns 0 while no procedure of yours is set.
Returns (GetWordBreakProc) the address of the procedure, or 0.
Example
' standalone
function SpaceBreak( byval lpch as wstring ptr, byval ichCurrent as long, byval cch as long, byval code as long ) as long
if code = WB_ISDELIMITER then return iif( lpch[ichCurrent] = 32, 1, 0 )
return ichCurrent
end function
sub UseSpaceBreak( byval hRich as HWND )
richedit.RichEdit.SetWordBreakProc( hRich, cast( LONG_PTR, @SpaceBreak ) )
end subMicrosoft Learn: EM_GETWORDBREAKPROC, EM_SETWORDBREAKPROC
function GetWordBreakProcEx( byval hRichEdit as HWND ) as LONG_PTR
function SetWordBreakProcEx( byval hRichEdit as HWND, byval pfn as LONG_PTR ) as LONG_PTRRead or replace the extended word-break procedure, an older form that gets the character set of the text as well. Current rich edit controls do not use it; use SetWordBreakProc.
Returns (GetWordBreakProcEx) the procedure's address, or 0; (SetWordBreakProcEx) the
previous one.
Example
dim pfnOld as LONG_PTR = richedit.RichEdit.GetWordBreakProcEx( hCtrl )Microsoft Learn: EM_GETWORDBREAKPROCEX, EM_SETWORDBREAKPROCEX
function GetAutoCorrectProc( byval hRichEdit as HWND ) as LONG_PTR
function SetAutoCorrectProc( byval hRichEdit as HWND, byval pfn as LONG_PTR ) as DWORDAn autocorrect procedure, of the AutoCorrectProc shape, is called as the user types and can
replace the word before the caret. GetAutoCorrectProc returns the one installed, or 0.
SetAutoCorrectProc sends pfn as the message's second parameter (lParam), while the control
reads the procedure from the first: the call returns nonzero but installs nothing, and
GetAutoCorrectProc still returns 0. To install a procedure, send the message with its address in
wParam, as the example does.
Returns (GetAutoCorrectProc) the procedure's address, or 0; (SetAutoCorrectProc) nonzero.
Example
' standalone
function NoCorrection( byval langid as LANGID, byval pszBefore as const wstring ptr, byval pszAfter as wstring ptr, byval cchAfter as LONG, byval pcchReplaced as LONG ptr ) as long
return ATP_NOCHANGE
end function
sub UseAutoCorrect( byval hRich as HWND )
SendMessageW( hRich, EM_SETAUTOCORRECTPROC, cast( WPARAM, @NoCorrection ), 0 )
if richedit.RichEdit.GetAutoCorrectProc( hRich ) = cast( LONG_PTR, @NoCorrection ) then print "installed"
end subMicrosoft Learn: EM_GETAUTOCORRECTPROC, EM_SETAUTOCORRECTPROC
function CallAutocorrectProc( byval hRichEdit as HWND, byval char as WCHAR ) as longCalls the installed autocorrect procedure as if the user had typed char, provided the text
before the caret is a candidate for correction.
Returns nonzero when the procedure was called.
Example
richedit.RichEdit.CallAutocorrectProc( hCtrl, 32 ) ' as if a space was typedMicrosoft Learn: EM_CALLAUTOCORRECTPROC
function GetPunctuation( byval hRichEdit as HWND, byval punctype as DWORD, byval lppunct as PUNCTUATION ptr ) as long
function SetPunctuation( byval hRichEdit as HWND, byval punctype as long, byval ppunct as PUNCTUATION ptr ) as longRead or set the punctuation characters used to break Asian text into lines. punctype picks the
set (PC_FOLLOWING, PC_LEADING, PC_OVERFLOW, PC_DELIMITER); the PUNCTUATION structure
holds a buffer (szPunctuation) and its size (iSize).
Returns nonzero on success.
Example
dim buf as zstring * 64
dim pu as PUNCTUATION
pu.iSize = sizeof( buf ) : pu.szPunctuation = @buf
richedit.RichEdit.GetPunctuation( hCtrl, PC_FOLLOWING, @pu )Microsoft Learn: EM_GETPUNCTUATION, EM_SETPUNCTUATION
function GetPageRotate( byval hRichEdit as HWND ) as DWORD
function SetPageRotate( byval hRichEdit as HWND, byval txtlayout as long ) as longRead or set the text layout: EPR_0 (left to right, top to bottom), EPR_90, EPR_180 or
EPR_270. Both are deprecated in Windows and kept for old code.
Returns the layout (for SetPageRotate, the new one).
Example
if richedit.RichEdit.GetPageRotate( hCtrl ) = EPR_0 then print "horizontal text"Microsoft Learn: EM_GETPAGEROTATE, EM_SETPAGEROTATE
function GetStoryType( byval hRichEdit as HWND, byval Index as DWORD ) as DWORD
function SetStoryType( byval hRichEdit as HWND, byval Index as long, byval dwType as DWORD ) as DWORDRead or set the type of story Index of the document (a story is a separate stream of text, such
as the main text or a footnote).
Returns the story type (for SetStoryType, the new type).
Example
dim nType as DWORD = richedit.RichEdit.GetStoryType( hCtrl, 0 )Microsoft Learn: EM_GETSTORYTYPE, EM_SETSTORYTYPE
function SetUIAName( byval hRichEdit as HWND, byval pwszName as wstring ptr ) as DWORDSets the name that UI Automation, and so a screen reader, reports for the control.
Returns nonzero on success.
Example
richedit.RichEdit.SetUIAName( hCtrl, "Notes" )Microsoft Learn: EM_SETUIANAME
sub SetPalette( byval hRichEdit as HWND, byval newPalette as HPALETTE )Gives the control the palette to draw with on a display with 256 colours or fewer.
Example
dim hPal as HPALETTE = CreateHalftonePalette( NULL )
richedit.RichEdit.SetPalette( hCtrl, hPal )Microsoft Learn: EM_SETPALETTE
function SetOleCallback( byval hRichEdit as HWND, byval pCallback as any ptr ) as longGives the control an IRichEditOleCallback object, through which it asks the program for
storage for embedded objects, its context menu and what may be pasted or dropped. The control
adds a reference of its own. CRichEditOleCallback is such an object.
Returns nonzero on success.
Example
dim pCallback as CRichEditOleCallback ptr = new CRichEditOleCallback
richedit.RichEdit.SetOleCallback( hCtrl, pCallback )Microsoft Learn: EM_SETOLECALLBACK
function GetOleInterface( byval hRichEdit as HWND, byval ppObject as IUnknown ptr ptr ) as longStores the control's IRichEditOle interface in *ppObject; from it the program can reach the
embedded objects and, with QueryInterface, the Text Object Model's ITextDocument. Release
the pointer when done.
Returns nonzero on success.
Example
dim pUnk as IUnknown ptr
if richedit.RichEdit.GetOleInterface( hCtrl, @pUnk ) then pUnk->lpVtbl->Release( pUnk )Microsoft Learn: EM_GETOLEINTERFACE
function GetZoom( byval hRichEdit as HWND, byval pzNum as DWORD ptr, byval pzDen as DWORD ptr ) as long
function SetZoom( byval hRichEdit as HWND, byval zNum as DWORD, byval zDen as DWORD ) as longThe zoom ratio is zNum / zDen, between 1/64 and 64. SetZoom( hCtrl, 3, 2 ) shows the text at
150 %, and 0, 0 turns zoom off. GetZoom stores the two numbers; both are 0 while no zoom is
set.
Returns nonzero on success.
Example
dim as DWORD zn, zd
richedit.RichEdit.SetZoom( hCtrl, 3, 2 )
richedit.RichEdit.GetZoom( hCtrl, @zn, @zd ) ' 3 and 2Microsoft Learn: EM_GETZOOM, EM_SETZOOM
function GetFirstVisibleLine( byval hRichEdit as HWND ) as longReturns the line shown at the top of the control.
Returns the line, counted from 0.
Example
print "top line"; richedit.RichEdit.GetFirstVisibleLine( hCtrl )Microsoft Learn: EM_GETFIRSTVISIBLELINE
function GetScrollPos( byval hRichEdit as HWND, byval lppt as POINT ptr ) as DWORD
function SetScrollPos( byval hRichEdit as HWND, byval pt as POINT ptr ) as DWORDRead or set how far the text is scrolled, as the point of the document, in pixels, shown at the top-left corner of the control. Save it before reloading the text and set it back afterwards to keep the view.
Returns 1.
Example
dim pt as POINT
richedit.RichEdit.GetScrollPos( hCtrl, @pt )
richedit.RichEdit.SetScrollPos( hCtrl, @pt )Microsoft Learn: EM_GETSCROLLPOS, EM_SETSCROLLPOS
function LineScroll( byval hRichEdit as HWND, byval y as long ) as longScrolls the text vertically by y lines: a positive number moves towards the end of the text, so
LineScroll( hCtrl, 5 ) from the top makes line 5 the first visible line.
Returns nonzero for a multiline control.
Example
richedit.RichEdit.LineScroll( hCtrl, 5 )Microsoft Learn: EM_LINESCROLL
function Scroll( byval hRichEdit as HWND, byval nAction as long ) as longScrolls the text vertically as a scroll bar would: nAction is SB_LINEUP, SB_LINEDOWN,
SB_PAGEUP or SB_PAGEDOWN.
Returns nonzero in the high word on success, with the number of lines scrolled in the low word.
Example
richedit.RichEdit.Scroll( hCtrl, SB_PAGEDOWN )Microsoft Learn: EM_SCROLL
sub ScrollCaret( byval hRichEdit as HWND )Scrolls the text so that the caret can be seen.
Example
richedit.RichEdit.SetSel( hCtrl, -1, -1 )
richedit.RichEdit.ScrollCaret( hCtrl )Microsoft Learn: EM_SCROLLCARET
function GetThumb( byval hRichEdit as HWND ) as longReturns the position of the scroll box in the vertical scroll bar.
Returns the position.
Example
print "thumb at"; richedit.RichEdit.GetThumb( hCtrl )Microsoft Learn: EM_GETTHUMB
sub ShowScrollBar( byval hRichEdit as HWND, byval nScrollBar as DWORD, byval fShow as long )Shows (fShow nonzero) or hides the horizontal (SB_HORZ) or vertical (SB_VERT) scroll bar of
a control created with that scroll bar.
Example
richedit.RichEdit.ShowScrollBar( hCtrl, SB_HORZ, false )Microsoft Learn: EM_SHOWSCROLLBAR
sub GetRect( byval hRichEdit as HWND, byval prc as RECT ptr )
sub SetRect( byval hRichEdit as HWND, byval fCoord as long, byval prect as RECT ptr )
sub SetRectNP( byval hRichEdit as HWND, byval fCoord as long, byval prect as RECT ptr )The formatting rectangle is the part of the control the text is laid out in. GetRect reads it,
in client coordinates; margins set with SetMargins narrow it. SetRect sets it
and redraws the control; SetRectNP sets it without redrawing. With fCoord 0, prect is in
client coordinates; with 1 its values are added to the current rectangle. NULL restores the
default.
Example
dim rc as RECT
richedit.RichEdit.GetRect( hCtrl, @rc )
rc.left += 8 : rc.right -= 8
richedit.RichEdit.SetRect( hCtrl, 0, @rc )Microsoft Learn: EM_GETRECT, EM_SETRECT, EM_SETRECTNP
sub SetMargins( byval hRichEdit as HWND, byval nMargins as long, byval nWidth as long )Sets the left and right margins, in pixels, and redraws the control. nMargins names the
margins to set (EC_LEFTMARGIN, EC_RIGHTMARGIN); nWidth holds the left one in its low word
and the right one in its high word. In a control 400 pixels wide, margins of 10 make the
formatting rectangle run from 10 to 390.
Example
richedit.RichEdit.SetMargins( hCtrl, EC_LEFTMARGIN or EC_RIGHTMARGIN, MAKELONG( 10, 10 ) )Microsoft Learn: EM_SETMARGINS
function SetTargetDevice( byval hRichEdit as HWND, byval hDC as HDC, byval lnwidth as long ) as longSets the device and line width the text is laid out for. With hDC NULL, lnwidth 0 wraps
lines at the edge of the control and 1 turns word wrap off. With a printer's device context and a
line width in twips, the text is laid out as it will print.
Returns nonzero on success.
Example
richedit.RichEdit.SetTargetDevice( hCtrl, NULL, 1 ) ' no word wrapMicrosoft Learn: EM_SETTARGETDEVICE
sub RequestResize( byval hRichEdit as HWND )Makes the control send its parent an EN_REQUESTRESIZE notification with the size its contents
need, which a control that grows with its text uses. ENM_REQUESTRESIZE must be in the event
mask.
Example
richedit.RichEdit.SetEventMask( hCtrl, ENM_REQUESTRESIZE )
richedit.RichEdit.RequestResize( hCtrl )Microsoft Learn: EM_REQUESTRESIZE
function StreamIn( byval hRichEdit as HWND, byval psf as long, byval pedst as EDITSTREAM ptr ) as DWORDReplaces the contents, or with SFF_SELECTION the selection, with data a callback supplies. psf
is the format, SF_TEXT or SF_RTF, optionally combined with SF_UNICODE and SFF_SELECTION.
The EDITSTREAM holds a value of your own (dwCookie) and the callback (pfnCallback), which the
control calls again and again with a buffer to fill, until it fills less than was asked or
returns nonzero. Afterwards dwError holds the callback's last nonzero return, or 0.
Returns the number of characters read.
Example
dim rtf as string = "{\rtf1\ansi Memory {\i RTF}}"
dim cd as RICHEDIT_CUSTOMDATA
cd.pData = cast( BYTE ptr, strptr( rtf ) ) : cd.nLen = len( rtf )
dim eds as EDITSTREAM
eds.dwCookie = cast( DWORD_PTR, @cd ) : eds.pfnCallback = cast( EDITSTREAMCALLBACK, @richedit.RichEdit.LoadRtfFromResourceCallback )
richedit.RichEdit.StreamIn( hCtrl, SF_RTF, @eds ) ' the control now reads "Memory RTF"Microsoft Learn: EM_STREAMIN, EditStreamCallback
function StreamOut( byval hRichEdit as HWND, byval psf as long, byval pedst as EDITSTREAM ptr ) as DWORDHands the contents, or with SFF_SELECTION the selection, to a callback in pieces: as plain text
with SF_TEXT or as RTF with SF_RTF. The callback gets each piece in its buffer, stores how
much it took in *pcb and returns 0 to go on.
Returns the number of characters written.
Example
' standalone
dim shared as string g_rtf
function CollectRtf( byval dwCookie as DWORD_PTR, byval pbBuff as BYTE ptr, byval cb as LONG, byval pcb as LONG ptr ) as DWORD
dim s as string = space( cb )
if cb then CopyMemory( strptr( s ), pbBuff, cb )
g_rtf &= s : *pcb = cb
return 0
end function
sub SaveRtf( byval hRich as HWND )
dim eds as EDITSTREAM
eds.pfnCallback = @CollectRtf
g_rtf = "" : richedit.RichEdit.StreamOut( hRich, SF_RTF, @eds ) ' g_rtf holds the document as RTF
end subMicrosoft Learn: EM_STREAMOUT
function LoadRtfFromFile( byval hRichEdit as HWND, byref wszFileName as wstring ) as booleanReplaces the contents of the control with an RTF file, streamed in with LoadRtfFromFileCallback. The file is opened for reading, shared with other readers, and closed again before the function returns.
| Parameter | Meaning |
|---|---|
wszFileName |
The path of the .rtf file. |
Returns true when text was read without error; false for a NULL handle, an empty name,
a file that cannot be opened, or a stream error.
Example
if richedit.RichEdit.LoadRtfFromFile( hCtrl, "readme.rtf" ) = false then print "could not load"Microsoft Learn: EM_STREAMIN, CreateFileW
function LoadRtfFromResource( byval hRichEdit as HWND, byval hInstance as HINSTANCE, byref wszResourceName as wstring ) as booleanReplaces the contents of the control with RTF kept as an RCDATA resource of the module
hInstance, under the name wszResourceName. The data is copied to a buffer and streamed in
with LoadRtfFromResourceCallback.
| Parameter | Meaning |
|---|---|
hInstance |
The module holding the resource, GetModuleHandleW( NULL ) for the program itself. |
wszResourceName |
The resource's name. |
Returns true when text was read without error; false for a NULL handle or instance, an
empty name, a resource that is not found, or a stream error.
Example
richedit.RichEdit.LoadRtfFromResource( hCtrl, GetModuleHandleW( NULL ), "HELPTEXT" )Microsoft Learn: FindResourceW, EM_STREAMIN
function LoadRtfFromFileCallback( byval hFile as HANDLE, byval lpBuff as byte ptr, byval cb as long, byval pcb as long ptr ) as UINTThe EditStreamCallback LoadRtfFromFile uses: it reads up to cb bytes from
the open file hFile (the dwCookie of the EDITSTREAM) into lpBuff and stores the number
read in *pcb. Use it with StreamIn to read a file you opened yourself, in any
SF_* format.
Returns 0, or the GetLastError code when the read fails.
Example
dim hFile as HANDLE = CreateFileW( "notes.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL )
dim eds as EDITSTREAM
eds.dwCookie = cast( DWORD_PTR, hFile ) : eds.pfnCallback = cast( EDITSTREAMCALLBACK, @richedit.RichEdit.LoadRtfFromFileCallback )
if hFile <> INVALID_HANDLE_VALUE then richedit.RichEdit.StreamIn( hCtrl, SF_TEXT, @eds ) : CloseHandle( hFile )Microsoft Learn: EditStreamCallback
function LoadRtfFromResourceCallback( byval pCustData as RICHEDIT_CUSTOMDATA ptr, byval lpBuff as byte ptr, byval cb as long, byval pcb as long ptr ) as DWORDThe EditStreamCallback LoadRtfFromResource uses: it copies the next
cb bytes, or what is left, of the block a RICHEDIT_CUSTOMDATA
describes (the dwCookie of the EDITSTREAM) into lpBuff, moves curPos on and stores the
number copied in *pcb. Use it with StreamIn for RTF or text held in memory.
Returns 0 while there was data to copy; 1, with *pcb set to 0, once the block is used up.
Example
dim buf as string = space( 4 )
dim as long nGot
dim rtf as string = "{\rtf1 abc}"
dim cd as RICHEDIT_CUSTOMDATA
cd.pData = cast( BYTE ptr, strptr( rtf ) ) : cd.nLen = len( rtf )
richedit.RichEdit.LoadRtfFromResourceCallback( @cd, cast( BYTE ptr, strptr( buf ) ), 4, @nGot ) ' buf is "{\rt", nGot 4Microsoft Learn: EditStreamCallback
function EnumFontFamProcW( byval lpelf as ENUMLOGFONTW ptr, byval lpntm as NEWTEXTMETRICW ptr, byval FontType as long, byval lplf as LOGFONTW ptr ) as longThe font enumeration callback SetFont uses. It copies the character set, pitch and
family and face name of the first font enumerated into the LOGFONTW passed as the
enumeration's lParam, and returns 0 to stop the enumeration there.
Returns 0.
Example
dim lf as LOGFONTW
dim hdc as HDC = GetDC( NULL )
EnumFontFamiliesW( hdc, "Consolas", cast( FONTENUMPROCW, @richedit.RichEdit.EnumFontFamProcW ), cast( LPARAM, @lf ) )
ReleaseDC( NULL, hdc ) ' lf.lfFaceName is "Consolas" when the font is installedMicrosoft Learn: EnumFontFamiliesW
function FormatRange( byval hRichEdit as HWND, byval fRender as long, byval lpfr as ..FORMATRANGE ptr ) as DWORDLays out a range of the text for a device, usually a printer, and with fRender nonzero draws
it. The FORMATRANGE names the device context to draw on (hdc) and to measure for
(hdcTarget), the area to draw in (rc) and the whole page (rcPage), both in twips, and the
range (chrg). Call it page after page, starting each from the value the last call returned.
Afterwards call it once with lpfr NULL to free what the control cached.
Returns the position of the first character that did not fit, where the next page starts.
Example
dim hdcPrn as HDC = GetDC( NULL ) ' a printer DC in a real program
dim fr as FORMATRANGE
fr.hdc = hdcPrn : fr.hdcTarget = hdcPrn
fr.rc.right = 12240 : fr.rc.bottom = 15840 : fr.rcPage = fr.rc ' 8.5 x 11 inches in twips
fr.chrg.cpMin = 0 : fr.chrg.cpMax = -1
dim nNext as long = richedit.RichEdit.FormatRange( hCtrl, true, @fr )
richedit.RichEdit.FormatRange( hCtrl, false, NULL ) : ReleaseDC( NULL, hdcPrn )Microsoft Learn: EM_FORMATRANGE
function DisplayBand( byval hRichEdit as HWND, byval lprc as RECT ptr ) as longDraws part of the text that FormatRange laid out with fRender 0, into the
rectangle lprc (in device units). Used to print a page in bands.
Returns nonzero on success.
Example
dim rc as RECT
rc.right = 600 : rc.bottom = 200
richedit.RichEdit.DisplayBand( hCtrl, @rc )Microsoft Learn: EM_DISPLAYBAND
function IsIME( byval hRichEdit as HWND ) as longTells whether the current input locale is East Asian, which uses an input method editor (IME).
Returns nonzero for an East Asian input locale.
Example
if richedit.RichEdit.IsIME( hCtrl ) then print "an IME is in use"Microsoft Learn: EM_ISIME
function GetIMECompMode( byval hRichEdit as HWND ) as DWORDReturns the IME composition mode: ICM_NOTOPEN (0) when no IME is open, otherwise an ICM_*
value.
Returns the mode.
Example
if richedit.RichEdit.GetIMECompMode( hCtrl ) = ICM_NOTOPEN then print "no IME open"Microsoft Learn: EM_GETIMECOMPMODE
function GetIMECompText( byval hRichEdit as HWND, byval lpict as IMECOMPTEXT ptr, byval buffer as any ptr ) as DWORDCopies the text the IME is composing into buffer. In the IMECOMPTEXT, cb is the buffer size
in bytes and flags is ICT_RESULTREADSTR.
Returns the number of characters copied.
Example
dim buf as wstring * 256
dim ict as IMECOMPTEXT
ict.cb = sizeof( buf ) : ict.flags = ICT_RESULTREADSTR
richedit.RichEdit.GetIMECompText( hCtrl, @ict, @buf )Microsoft Learn: EM_GETIMECOMPTEXT
function GetIMEColor( byval hRichEdit as HWND, byval rgCmpclr as COMPCOLOR ptr ) as long
function SetIMEColor( byval hRichEdit as HWND, byval pcompcolor as COMPCOLOR ptr ) as longRead or set the colours of IME composition text: an array of four COMPCOLOR, one per stage of
composition, each with text and background colours and effects.
Returns nonzero on success.
Example
dim cc( 0 to 3 ) as COMPCOLOR
richedit.RichEdit.GetIMEColor( hCtrl, @cc( 0 ) )Microsoft Learn: EM_GETIMECOLOR, EM_SETIMECOLOR
function GetIMEModeBias( byval hRichEdit as HWND ) as DWORD
function SetIMEModeBias( byval hRichEdit as HWND, byval nModeBias as long ) as longRead or set the IME mode bias, the kind of input the IME should expect (IMF_SMODE_PLAURALCLAUSE,
IMF_SMODE_NONE). SetIMEModeBias sends nModeBias as both the bias and the mask of bits to
change.
Returns the mode bias (for SetIMEModeBias, the new one).
Example
richedit.RichEdit.SetIMEModeBias( hCtrl, IMF_SMODE_PLAURALCLAUSE )Microsoft Learn: EM_GETIMEMODEBIAS, EM_SETIMEMODEBIAS
function GetIMEOptions( byval hRichEdit as HWND ) as DWORD
function SetIMEOptions( byval hRichEdit as HWND, byval fCoop as long, byval fOptions as long ) as longRead or change the IMF_* IME options (IMF_FORCEENABLE, IMF_CLOSESTATUSWINDOW …); fCoop
says how fOptions combines with the current ones: ECOOP_SET, ECOOP_OR, ECOOP_AND or
ECOOP_XOR.
Returns (GetIMEOptions) the options; (SetIMEOptions) nonzero on success.
Example
richedit.RichEdit.SetIMEOptions( hCtrl, ECOOP_OR, IMF_CLOSESTATUSWINDOW )Microsoft Learn: EM_GETIMEOPTIONS, EM_SETIMEOPTIONS
function GetIMEProperty( byval hRichEdit as HWND, byval figp as DWORD ) as DWORDReturns a property of the IME of the current input locale; figp picks which: IGP_PROPERTY,
IGP_CONVERSION, IGP_SENTENCE, IGP_UI, IGP_SETCOMPSTR, IGP_SELECT or IGP_GETIMEVERSION.
Returns the property's value.
Example
dim nProps as DWORD = richedit.RichEdit.GetIMEProperty( hCtrl, IGP_PROPERTY )Microsoft Learn: EM_GETIMEPROPERTY
function GetLangOptions( byval hRichEdit as HWND ) as DWORD
function SetLangOptions( byval hRichEdit as HWND, byval lgoptions as long ) as DWORDRead or set the options for IMEs and for text in several languages: IMF_AUTOFONT (switch fonts
when the keyboard language changes), IMF_AUTOKEYBOARD, IMF_DUALFONT, IMF_UIFONTS …
SetLangOptions replaces them all; or with GetLangOptions to add one.
Returns (GetLangOptions) the options; (SetLangOptions) nonzero.
Example
richedit.RichEdit.SetLangOptions( hCtrl, richedit.RichEdit.GetLangOptions( hCtrl ) and not IMF_AUTOFONT )Microsoft Learn: EM_GETLANGOPTIONS, EM_SETLANGOPTIONS
function GetCTFModeBias( byval hRichEdit as HWND ) as long
function SetCTFModeBias( byval hRichEdit as HWND, byval nModeBias as long ) as longRead or set the Text Services Framework mode bias, the kind of input expected: CTFMODEBIAS_DEFAULT,
CTFMODEBIAS_FILENAME, CTFMODEBIAS_NAME, CTFMODEBIAS_NUMERIC and others.
Returns the mode bias (for SetCTFModeBias, the new one).
Example
richedit.RichEdit.SetCTFModeBias( hCtrl, CTFMODEBIAS_NUMERIC )Microsoft Learn: EM_GETCTFMODEBIAS, EM_SETCTFMODEBIAS
function GetCTFOpenStatus( byval hRichEdit as HWND ) as long
function SetCTFOpenStatus( byval hRichEdit as HWND, byval fTSFkbd as long ) as DWORDRead whether the Text Services Framework keyboard is open, or open (fTSFkbd nonzero) or close
it.
Returns (GetCTFOpenStatus) nonzero when it is open; (SetCTFOpenStatus) nonzero on
success.
Example
if richedit.RichEdit.GetCTFOpenStatus( hCtrl ) then richedit.RichEdit.SetCTFOpenStatus( hCtrl, false )Microsoft Learn: EM_GETCTFOPENSTATUS, EM_SETCTFOPENSTATUS
function Reconversion( byval hRichEdit as HWND ) as DWORDOpens the IME reconversion dialog for the selected text.
Returns 0.
Example
richedit.RichEdit.Reconversion( hCtrl )Microsoft Learn: EM_RECONVERSION
type RICHEDIT_CUSTOMDATA
pData as byte ptr
nLen as long
curPos as long
end typeDescribes a block of data in memory for LoadRtfFromResourceCallback:
pData points to the data, nLen is its length in bytes and curPos how much has been read so
far, 0 to start. The type is declared outside the RichEdit namespace: after using richedit
it is written RICHEDIT_CUSTOMDATA. The data must stay in place until the stream ends.
Example
dim rtf as string = "{\rtf1 Hello}"
dim cd as RICHEDIT_CUSTOMDATA
cd.pData = cast( BYTE ptr, strptr( rtf ) ) : cd.nLen = len( rtf ) : cd.curPos = 0- sys/win/richedit for the module and its three ways of working with a rich edit control
- CRichEditCtx, the class that creates a rich edit control and wraps these messages as members
- CRichEditCtx: editing and CRichEditCtx: document
- Text Object Model and CTextRange2 for formatting through TOM
- CRichEditOleCallback for SetOleCallback
- Edit for the plain edit control's functions
-
CWindow for
AddControl( "RichEdit", ... )
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing