No announcement yet.

Rich Edit Messages - EM_ReplaceSel vs EM_SetTextEX

  • Filter
  • Time
  • Show
Clear All
new posts

  • Rich Edit Messages - EM_ReplaceSel vs EM_SetTextEX

    The MSDN description of EM_ReplaceSel doesn't seem to clarify whether EM_SetTextEX should be used to replace EM_ReplaceSel, or whether EM_SetTextEX simply has more features (RTF, code page, ...) and that using EM_ReplaceSel is fine if you don't need the additional features of EM_SetTextEX.

    EM_ReplaceSel is found in the Edit Control messages section, but doesn't mention any constraints in using it with a Rich Edit control.

    Can someone clarify?

  • #2
    Don't know if this will clarify much but browsing the SDK Documentation, I cut-n-pasted the following:
    The EM_REPLACESEL message replaces the current selection in an edit control with the specified text.
    You can send this message to either an edit control or a rich edit control.
    To replace all of the text, use the WM_SETTEXT message.

    If there is no current selection, the replacement text is inserted at the current location of the caret.

    Supported in Microsoft Rich Edit 1.0 and later.
    Minimum operating systems Windows 95, Windows NT 3.1
    >> Rich Edit 1.0 <=> Riched32.dll (Control class name "RichEdit")

    The EM_SETTEXTEX message 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.

    Pointer to a SETTEXTEX structure that specifies flags and an optional code page to use in translating to Unicode.
    Pointer to the null-terminated text to insert. This text is an ANSI string, unless the code page is 1200 (Unicode),
    in which case it's a Unicode string. If lParam starts with a valid RTF ASCII sequence,
    for example, {\rtf or {urtf, the text is read in using the RTF reader. This allows one to set rich text.

    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.

    Minimum operating systems Windows 95 with Rich Edit 3.0, Windows NT 4.0 with Rich Edit 3.0, Windows Millennium Edition, Windows 2000
    >> Rich Edit 3.0 <=> Riched20.dll (Control class name "RichEdit20A", "RichEdit20W")
    So while the two messages share some functionality which you use will depend somewhat on which version of Rich Edit you are using and also whether you are inserting plain / rich text, Ansii or Unicode..
    Rgds, Dave


    • #3
      Dave, thanks for the response.

      The way I read that, there is NO constraint on the EM_ReplaceSel - making it compatible with RichEdit controls.

      Since that are some messages whose ability to support RichEdit controls is limited to 64K, it makes me wonder about the rest of the messages - those which don't clarify if there are any limitations. EM_ReplaceSel fell into that category.

      Since EM_SetTextEX is a bit more convoluted to use, I'd rather stick with EM_ReplaceSel when I can.