tags:

views:

21

answers:

1

I have a situation where I must use Windows API to retrieve text from a Rich Text Box in another program; I am wondering if there is any way to get the ...'rich text' from it, and not just the plain text.

In this example, ptrHandle is the RichText Control Handle.

if (ptrHandle == null)
    return null;

if (ptrHandle == IntPtr.Zero)
    return null;

IntPtr ptrLength =
    SendMessage(ptrHandle, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);

var nLen = ptrLength.ToInt32();

if (nLen <= 0)
    return null;
var strBuffer = new System.Text.StringBuilder(nLen + 1);

SendMessage(ptrHandle, WM_GETTEXT, new IntPtr(nLen + 1), strBuffer);

This is all done in C#. It gets the text out just fine, but it's stripped of formatting, and such. I was hoping I could retrieve all of that as well.

+1  A: 

Good news: EM_STREAMOUT helps you retrieve the RTF, the kind that has the formatting. Bad news: you cannot make that work without injecting a DLL into the process since it requires a callback. You can't make that work in C#, native C/C++ is required. I know, not helpful.

Hans Passant
Damn. is there any way to wrap the behavior into a C++ dll and load it into .NET?
Stacey