Help Center

CRichEditCtx.InsertTextmethod

Inserts text at the specified location.

Windowsmethoddocumented

Syntax

FUNCTION InsertText OVERLOAD (BYREF strText AS STRING) AS DWORD
FUNCTION InsertText OVERLOAD (BYREF wszText AS WSTRING) AS DWORD
FUNCTION InsertText OVERLOAD (BYVAL nPos AS LONG, BYREF strText AS STRING) AS DWORD
FUNCTION InsertText OVERLOAD (BYVAL nPos AS LONG, BYREF wszText AS WSTRING) AS DWORD
Also documented as ReplaceText, SetTextEx — one description covers them all.

Parameters

NameDescription
stexA SETTEXTEX structure that specifies flags and an optional code page to use in translating to Unicode.
bufferPointer to the null-terminated text to insert. This text is an ANSI string, unless the code page is 1200 (Unicode). If pwszText starts with a valid RTF ASCII sequence for example, "{\rtf" or "{urtf" the text is read in using the RTF reader.
nStartStart position.
nEndEnd position.
nPosPosition.
strTextAnsi text.
wszTextUnicode text.

Return value

If the operation is setting all of the text and succeeds, the return value is 1.

If the operation is setting the selection and succeeds, the return value is the number of bytes or characters copied.

If the operation fails, the return value is zero.

Description

Combines the functionality of WM_SETTEXT and EM_REPLACESEL and adds the ability to set text using a code page and to use either Rich Text Format (RTF) rich text or plain text.

SETTEXTEX flags

Option flags. It can be any reasonable combination of the following flags.

SETTEXTEX codepage

The code page used to translate the text to Unicode. If codepage is 1200 (Unicode code page), no translation is done. If codepage is CP_ACP, the system code page is used.

Examples

DIM stex AS .SETTEXTEX stex.flags = ST_SELECTION OR ST_KEEPUNDO stex.codepage = CP_ACP DIM st AS STRING = "New text" pRichEdit->SetTextEx(stex, st) --or-- pRichEdit->SetTextEx(st) --or-- pRichEdit->InsertTextEx(st)

DIM stex AS .SETTEXTEX stex.flags = ST_SELECTION OR ST_KEEPUNDO stex.codepage = CP_ACP DIM st AS STRING = $"{\rtf1\ansi New text}" pRichEdit->SetTextEx(stex, st) --or-- pRichEdit->SetTextEx(st) --or-- pRichEdit->InsertTextEx(st)

DIM stex AS .SETTEXTEX stex.flags = ST_SELECTION OR ST_KEEPUNDO stex.codepage = 1200 DIM wsz AS WSTRING * 10 = "New text" pRichEdit->SetTextEx(stex, wsz) --or-- pRichEdit->SetTextEx(wsz) --or-- pRichEdit->InsertTextEx(wsz)

DIM stex AS .SETTEXTEX stex.flags = ST_SELECTION OR ST_KEEPUNDO stex.codepage = 1200 DIM sws AS DWSTRING = "New text" pRichEdit->SetTextEx(stex, dws) --or-- pRichEdit->SetTextEx(dws) --or-- pRichEdit->InsertTextEx(dws)

pRichEdit->SetTextEx (10, 20, "New Text")

DIM st AS STRING = "New text" pRichEdit->SetTextEx (10, 20, st)

DIM st AS STRING = $"{\rtf1\ansi New text}" pRichEdit->SetTextEx (10, 20, st)

DIM wsz AS WSTRING * 10 = "New text" pRichEdit->SetTextEx (10, 20, wsz)

DIM dws AS DWSTRING = "New text" pRichEdit->SetTextEx (10, 20, dws)

pRichEdit->SetTextEx (10, "New Text")

DIM st AS STRING = "New text" pRichEdit->SetTextEx (10, st)

DIM st AS STRING = $"{\rtf1\ansi New text}" pRichEdit->SetTextEx (10, st)

DIM wsz AS WSTRING * 10 = "New text" pRichEdit->SetTextEx (10, wsz)

DIM dws AS DWSTRING = "New text" pRichEdit->SetTextEx (10, dws)

pRichEdit->SetTextEx (10, 20, "")

Inserts ansi text at the caret position: Inserts formatted rich text at the caret position: Inserts unicode text at the caret position: Replaces text Inserts text at the specified position: Delete text:

Reference

  • Defined in AfxNova/CRichEditCtx.inc:2483
  • Documented in Windows/WIndows Controls/RichEdit/CRichEditCtx Class.md
  • Topic: CRichEditCtx Class