0

In win32, how do I setup a callback mechanism for RichEdit I have not created myself?

PART 1

I'm reading from a textedit field in another application's GUI. This works just fine now, except after the first read I'd like to fetch only new or modified lines. In GTK+ or Qt I'd just install a callback on some signal the field edits when its changed, but how does it work on Win32?

My MSDN searches result with nothing useful, probably because I don't know the exact term to search for. The class of the textedit is RichText20W, and it has some messages that are probably used somehow, though that article just discusses using them for the parent of the class.

PART 2

Also, if there is no such "text changed, here is the newly inserted text" callback which returns the new content immediately, I need some way to easily detect what is new. From top-of-my-head:

  1. Have a marker at the end of the text block we've read, and only read between that and the end.
  2. Store what we've read previously, and after a second read, remove the duplicate part from the latter to have the newly inserted stuff.

Option 2 might not be viable, since the textedit can contain any amount of text. The marker part sounds doable, but yet again, my feeble Win32 skills and horrible Win32 function names prevent me from finding the right way to do it.

Note that all these must be doable for a textedit I do not own and have not created, they belong to a third party process.

Code samples in C++ highly appreciated.

Disclaimer

Obviously, if there is some better way of doing it, let me know. I only assumed callback would be the way to go based on my previous experience with GTK+/Qt. Feel free to show me the path :)

4

3 に答える 3

1

Win32 コントロールは、サブスクライブできるメッセージ固有のコールバックでは機能しません。何かが発生したときに、親ウィンドウにメッセージを送信するだけです。この場合は、EN_UPDATE、EN_CHANGE などです。これらのイベントでさえ、どのテキストが変更されたかはわかりません。彼らはそれ変わったとあなたに言うだけです。

親をサブクラス化することはできますが、SetWindowLongPtr のドキュメントには、「別のプロセスによって作成されたウィンドウ クラスをサブクラス化しないでください」と明示的に記載されています。このようなことはおそらくフックで可能ですが、実際にどのように行うかを確実に述べるには十分ではありません。

于 2008-12-22T18:48:51.243 に答える
0

ジョエルの答えに基づいて、私はコールバックを探すのをやめ、(実際の API フックではなく) 自分自身をリッチエディットにフックし、コンテンツの長さを 1 秒に 1 回ポーリングする小さなクラスを作成しました。 、コンテンツを要求し、それを以前の既知のコンテンツと比較し、変更されたコンテンツで信号を発します。

これはこの目的には問題ないようですが、誰かがより良い方法 (API フックなどを介して実際にテストされた方法) を知っている場合は、投稿してください。

于 2008-12-24T09:25:13.640 に答える