[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
public const int WM_SETTEXT = 0x000c;
internal void SendText(string content)
{
var notepads = System.Diagnostics.Process.GetProcessesByName("notepad");
if (notepads.Length > 0 && notepads[0] != null)
{
IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
SendMessage(child, WM_SETTEXT, 0, content);
}
}