1. using System; 
  2. using System.Collections.Generic; 
  3. using System.ComponentModel; 
  4. using System.Data; 
  5. using System.Drawing; 
  6. using System.Text; 
  7. using System.Windows.Forms; 
  8. using System.Runtime.InteropServices; 
  9. using System.Diagnostics; 
  10.  
  11. namespace send2notepad 
  12.     public partial class Form1 : Form 
  13.     { 
  14.         [DllImport("User32.dll ")] 
  15.         public static extern IntPtr FindWindow(string ClassName, string CaptionName); 
  16.         [DllImport("User32.dll ")] 
  17.         public static extern int SendMessage(IntPtr hwad, int wMsg, int lParam, int wParam); 
  18.  
  19.         [DllImport("user32.dll")] 
  20.         public static extern IntPtr SetFocus(IntPtr hwnd2); 
  21.  
  22.         [DllImport("user32.dll")] 
  23.         public static extern IntPtr FindWindowEx(IntPtr parenthW, IntPtr child, string s1, string s2); 
  24.  
  25.         public const int WM_SETTEXT = 0x000C; 
  26.         public const int WM_CHAR = 0x0102;  
  27.  
  28.  
  29.         public Form1() 
  30.         { 
  31.  
  32.             InitializeComponent(); 
  33.             //System.Diagnostics.Process txt = Process.Start(@"notepad"); 
  34.             Process txt = Process.Start("notepad","test");   
  35.         } 
  36.  
  37.         private void button1_Click(object sender, EventArgs e) 
  38.         { 
  39.              
  40.             string className = "Notepad"
  41.             //string className = "winword"; 
  42.  
  43.             string captionName = "test.txt - 记事本"
  44.  
  45.             IntPtr hwnd = FindWindow(null, captionName);//找主窗口. 
  46.  
  47.  
  48.             IntPtr hwnd2 = FindWindowEx(hwnd, IntPtr.Zero, "Edit""");  //  找子窗体 
  49.             //SendMessage(hwnd22,256,97,0); 
  50.  
  51.             if (hwnd2.Equals( IntPtr.Zero)) 
  52.             { 
  53.                 MessageBox.Show("can't find window!"); 
  54.                 return
  55.             } 
  56.  
  57.             SendMessage(hwnd2, WM_CHAR, (int)'h', 0); 
  58.             SendMessage(hwnd2, WM_CHAR, (int)'e', 0); 
  59.             SendMessage(hwnd2, WM_CHAR, (int)'l', 0); 
  60.             SendMessage(hwnd2, WM_CHAR, (int)'l', 0); 
  61.             SendMessage(hwnd2, WM_CHAR, (int)'o', 0);   
  62.  
  63.  
  64.         } 
  65.     }