How to set up a callback mechanism for RichEdit in win32

In win32, how do I set up a callback mechanism for RichEdit I haven't created myself?

PART 1

I am reading from textedit field in another GUI application . Now this works fine, only after the first reading I would like to get only new or changed lines. In GTK + or Qt, I would just set a callback on some signal by editing the field when it was changed, but how does it work on Win32?

My MSDN search results are nothing useful, probably because I don't know the exact search term. The textedit class is RichText20W , and it has messages that are probably used in some way, although this article is just discussing the use of them for the parent of the class.

PART 2

Also, if there is no such "changed text", it is a new callback that immediately returns new content, I need to somehow easily determine what is new. From the top of your head:

  • You have a bullet at the end of the text block that we read, and we only read this to the end.
  • Save what we read earlier and after the second reading, remove the duplicated part from the last one to have the newly inserted material.

Option 2 may not be practical because textedit can contain any amount of text. The bullet part sounds doable, but then again, my poor Win32 skills and terrible Win32 function names are preventing me from finding the right way to do this.

Note that all of this must be done for textedit i not and not created, they belong to a third party process.

Code examples in C ++ are highly appreciated.

Denial of responsibility

Obviously if there is a better way to do this, let me know. I assumed the callback would be in a way based on my previous experience with GTK + / Qt. Feel free to show me the way :)

0


source to share


3 answers


Win32 controls don't work with callbacks that you can subscribe to. They just send messages to the parent window when something happens, in this case EN_UPDATE, EN_CHANGE and all that. Even these events don't tell you which text has changed. They only tell you that it has changed.



You can subclass the parent, but the documentation for SetWindowLongPtr explicitly states that you "should not subclass a window class created by another process." Something similar to hooks perhaps, but I haven't used them enough to tell you exactly how you actually do it.

+1


source


I understand this old post, but this article seems to be doing something similar.



+1


source


Based on Joel's answer, I stopped looking for callbacks and just made a small class that itself intercepts (not really an API) to richedit and polls it once a second for the length of the content and if it has changed since the last poll , it queries the content, compares it to the previously known content, and emits a signal with the changed content.

It seems to work fine for this purpose, but if anyone knows even better (some real and proven way to do this via API interceptors or whatever) please post.

0


source







All Articles