1 using System.Reflection; 2 3 [DllImport("user32.dll", EntryPoint="FindWindow")] 4 public static extern int FindWindow ( 5 string lpClassName, 6 string lpWindowName 7 ); 8 9 [DllImport("user32.dll", EntryPoint="FindWindowEx")] 10 public static extern int FindWindowEx ( 11 int hWnd1, 12 int hWnd2, 13 string lpsz1, 14 string lpsz2 15 ); 16 17 [DllImport("user32.dll", EntryPoint="SendMessage")] 18 public static extern int SendMessage ( 19 int hwnd, 20 int wMsg, 21 int wParam, 22 System.Text.StringBuilder lParam 23 ); 24 25 private void button1_Click(object sender, System.EventArgs e) 26 { 27 int hwnd = FindWindow("notepad", null); 28 hwnd = FindWindowEx(hwnd, 0, "Edit", null); 29 System.Text.StringBuilder str = new System.Text.StringBuilder(255); 30 SendMessage(hwnd, 0xD, str.Capacity, str); 31 MessageBox.Show(str.ToString()); 32 }
先获取所要窗口的句柄(你可用spy++查相关的参数)
然后用GetWindowText这个API函数