码迷,mamicode.com
首页 > 其他好文 > 详细

获取任意进程的文本内容值

时间:2014-09-11 13:50:41      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   div   sp   cti   

 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函数

获取任意进程的文本内容值

标签:style   blog   color   io   os   ar   div   sp   cti   

原文地址:http://www.cnblogs.com/yomho/p/3966280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!