【发布时间】:2010-08-18 04:59:46
【问题描述】:
我有一种情况,我必须使用 Windows API 从另一个程序的富文本框中检索文本;我想知道是否有任何方法可以从中获取...“富文本”,而不仅仅是纯文本。
在本例中,ptrHandle 是 RichText 控件句柄。
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);
这一切都是在 C# 中完成的。它可以很好地输出文本,但它没有格式等。我希望我也能找回所有这些。
【问题讨论】: