|
Part of the code is as follows:
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);
Among them, MainWindowHandle is the handle of the main window of another program. After obtaining one of the handles of RichEdit, you want to get the text in it.
But lpstrText in TR is empty after SendMessage is executed. Please help me to find out what is wrong. |
|