You could use some win32 functions to get the text content of an external control. You gave the example of notepad:
Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace gettext
{
class Program
{
static void Main(string[] args)
{
foreach (Process proc in Process.GetProcesses())
if (proc.ProcessName == "notepad")
{
IntPtr ptr = proc.MainWindowHandle;
ptr = FindWindowEx(ptr, IntPtr.Zero, "Edit", IntPtr.Zero);
Console.WriteLine(GetWindowText(ptr));
}
Console.Read();
}
public static string GetWindowText(IntPtr hwnd)
{
int len = SendMessageGetTextLength(hwnd, 14, IntPtr.Zero, IntPtr.Zero);
StringBuilder sb = new StringBuilder(len);
SendMessageGetText(hwnd, 13, new UIntPtr((uint)len), sb);
return sb.ToString();
}
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent,
IntPtr hwndChildAfter, string lpszClass, IntPtr lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern IntPtr SendMessageGetText(IntPtr hWnd,
uint msg, UIntPtr wParam, StringBuilder lParam);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private extern static int SendMessageGetTextLength(IntPtr hWnd,
int msg, IntPtr wParam, IntPtr lParam);
}
}
Notice this line:
Code:
ptr = FindWindowEx(ptr, IntPtr.Zero, "Edit", IntPtr.Zero);
I got the "Edit" class name by using Spy++.
Unfortunately I don't think there is a managed way of achieving what you require, but I'd be happy for someone to prove me wrong.