|
部分代码如下:
struct CHARRANGE
{
long cpMin;
long cpMax;
}
struct TEXTRANGE
{
CHRANGE chrg;
string lpstrText;
}
CHARRANGE CR;
TEXTRANGE TR = new TEXTRANGE();
IntPtr hWndOutPut = FindWindowEx(MainWindowHandle, IntPtr.Zero, "RICHEDIT", "");
int lineCount = SendMessage(hWndOutPut, EM_GETLINECOUNT, 0, ref TR);
int lc = SendMessage(hWndOutPut, EM_LINELENGTH, 0, ref TR);
int charFrom = SendMessage(hWndOutPut, EM_LINEINDEX, lineCount - 1, ref TR);
int charEnd = charFrom + lc;
CR.cpMin = charFrom;
CR.cpMax = charEnd;
TR.chrg = CR;
TR.lpstrText = new String('\0',10240);
SendMessage(hWndOutPut, EM_GETTEXTRANGE, 0, ref TR);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref TEXTRANGE lParam);
其中MainWindowHandle是另外一个程序的主窗口的句柄,获取其中一个RichEdit的句柄后,想获得其中的文本,
但SendMessage执行后TR中lpstrText为空,请大家帮帮我,找出错误所在。 |
|