C#调用API访问其它进程
2007-03-09 09:17
549 查看
近段时间由于工作的需要访问其它进程的相关数据,现将其中的一些代码写下来,以备参考.
代码如下(系统自动生成的没有列出来):
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Runtime.InteropServices;
9
10namespace WindowsApplication1
11{
12 public partial class Form1 : Form
13 {
14 [DllImport("User32.dll", EntryPoint = "FindWindow")]
15 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
16
17 [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
18 private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
19
20 [DllImport("User32.dll", EntryPoint = "SendMessage")]
21 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
22
23 public Form1()
24 {
25 InitializeComponent();
26 }
27
28 private void button1_Click(object sender, EventArgs e)
29 {
30 const int WM_GETTEXT = 0x000D;
31
32 string lpszParentClass = "Form";
33 string lpszParentWindow = "Form1";
34 string lpszClass = "Button";
35
36 string getTxt = "";
37 IntPtr ParenthWnd = new IntPtr(0);
38 IntPtr EdithWnd = new IntPtr(0);
39
40 ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
41 if (!ParenthWnd.Equals(IntPtr.Zero))
42 {
43 EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
44 if (!EdithWnd.Equals(IntPtr.Zero))
45 {
46 SendMessage(EdithWnd, WM_GETTEXT, (IntPtr)0, getTxt);
47 if (getTxt.Length != 0)
48 {
49 MessageBox.Show(getTxt);
50 }
51 }
52
53 }
54 }
55 }
56}
转:http://www.cnblogs.com/dongjie/archive/2006/12/16/594197.html
代码如下(系统自动生成的没有列出来):
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Runtime.InteropServices;
9
10namespace WindowsApplication1
11{
12 public partial class Form1 : Form
13 {
14 [DllImport("User32.dll", EntryPoint = "FindWindow")]
15 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
16
17 [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
18 private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
19
20 [DllImport("User32.dll", EntryPoint = "SendMessage")]
21 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
22
23 public Form1()
24 {
25 InitializeComponent();
26 }
27
28 private void button1_Click(object sender, EventArgs e)
29 {
30 const int WM_GETTEXT = 0x000D;
31
32 string lpszParentClass = "Form";
33 string lpszParentWindow = "Form1";
34 string lpszClass = "Button";
35
36 string getTxt = "";
37 IntPtr ParenthWnd = new IntPtr(0);
38 IntPtr EdithWnd = new IntPtr(0);
39
40 ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
41 if (!ParenthWnd.Equals(IntPtr.Zero))
42 {
43 EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
44 if (!EdithWnd.Equals(IntPtr.Zero))
45 {
46 SendMessage(EdithWnd, WM_GETTEXT, (IntPtr)0, getTxt);
47 if (getTxt.Length != 0)
48 {
49 MessageBox.Show(getTxt);
50 }
51 }
52
53 }
54 }
55 }
56}
转:http://www.cnblogs.com/dongjie/archive/2006/12/16/594197.html
相关文章推荐
- C#调用API访问其它进程
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信及C# 获得另外一程序 句柄 后控制该程序 控制其透明 窗体大小
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- 用C#调用Windows API和其它进程通信
- SilverLight OOB模式与Com API交换的基础 和 C#编写Com 组件在SilverLight调用
- C++数据类型与C#对应关系 c#调用WINDWOS API时,非常有用
- Linux下通过系统调用(API)和C语言库函数对文件进行访问