3

I want to get the entire text in a rich edit control as a CString, and from my reaseach there appear to be six ways of achieving this:

  1. GetTextRange and get the range by using GetTextLength
  2. EM_GETTEXTEX
  3. GetWindowText
  4. GetDlgItemText
  5. WM_GETETXT
  6. EM_STREAMOUT

My questions are as follows:

  1. What is the difference between using methods such as GetTextRange, GetWindowText, and GetDlgItemText versus using messages such as EM_GETTEXTEX, WM_GETETXT, and EM_STREAMOUT.
  2. When would you use one type, and when would you use another?
  3. What is the difference between EM_GETTEXTEX, WM_GETETXT, and EM_STREAMOUT in terms of accomplishing this task of getting the entire text in a rich edit control as a CString?
  4. Finally would it be possible for someone to provide an example of how to use EM_GETTEXTEX, or point me in the direction of one online?
johnsyweb
  • 136,902
  • 23
  • 188
  • 247
user3126297
  • 159
  • 2
  • 3
  • 10
  • `GetTextRange`, `GetWindowText` and `GetDlgItemText` are more or less wrappers around window messages such as `WM_GETTEXT` which are more convenient to use. This is also why you'd generally prefer to use these versions. The arguments are more typesafe than `SendMessage`'s `LPARAM` and `WPARAM` parameters and require no casts. Look at the MSDN documentation of these functions and you'll see that the documentation mentions that the appropriate window messages are being sent. – j_schultz Dec 22 '13 at 00:44
  • With WM_GETTEXT you may retrieve text from control belongs another process. GetWindowText dont retrieve this. GetDlgItemText is conceptual same as the GetWindowText, but allow ID of control instead of control hwnd. – Xearinox Dec 22 '13 at 00:47
  • Just wanted to add this. With WM_GETTEXT and wrappers you get the text as is, unformatted. It is very useful to get the text only from the control. With EM_STREAMOUT you retrieve the rtf contents of the document – cha Dec 22 '13 at 08:58

1 Answers1

1

All are the same, except EM_STREAMOUT.

No. 1 to 5 just get the plain text. No. 6 gets the complete RTF stream. So No. 1. to 5. are just methods that do nearly the same as sending WM_GETTEXT.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • `GetWindowText` is very different from sending a `WM_GETTEXT` message: [The secret life of GetWindowText](http://blogs.msdn.com/b/oldnewthing/archive/2003/08/21/54675.aspx). – IInspectable Dec 23 '13 at 19:04
  • Agree. But as we are talking about this function in process, and specific to an edit/rtf control I see no difference in the usage here. – xMRi Dec 23 '13 at 22:01
  • The question asks about the differences and why there are 6 different ways to do the same thing. An answer that unconditionally says, they are all the same, is wrong. Even if the differences do not matter in the implied use case, they still need to be noted. Surely you wouldn't say that multiplication and division perform the same operation (as long as they're used with 1). – IInspectable Dec 23 '13 at 22:10