Carefully minded will spot at least one subtle difference between the Visual Studio editor, and the
RichEdit control: the caret in selection. Why oh why I can get this cute blinking cursor when I select some text in Visual Studio, but not in WordPad or in
RichTextBox?
Maybe it's hidden for some bizarre reasons, I'll just call
ShowCaret to bring it back. Argh, doesn't work? OK, may be
HideCaret is called multiple times, so I'll just call ShowCaret a zillion times to see what gives. What? The caret is actually destroyed, and I have to call
CreateCaret?
How am I supposed to know the height of the caret? It's not exactly
Font.
Height, and I can't always get the position of two lines and take the difference.
Text Object Model (TOM) comes into rescue. It's implemented by RichEdit (not
Edit, so no hope there, yet). Get an
IRichEditOle with
EM_GETOLEINTERFACE, then an
ITextDocument, then an
ITextRange from ITextDocument::
Range, and finally the coordinates from ITextRange::
GetPoint.
I'll leave it as an exercise to declare the TOM interfaces for .net. Yea this whole thing is purely artistic...