C#调用API访问其它进程

近段时间由于工作的需要访问其它进程的相关数据,现将其中的一些代码写下来,以备参考.
    代码如下(系统自动生成的没有列出来): 
 1 None.gif using  System;
 2 None.gif using  System.Collections.Generic;
 3 None.gif using  System.ComponentModel;
 4 None.gif using  System.Data;
 5 None.gif using  System.Drawing;
 6 None.gif using  System.Text;
 7 None.gif using  System.Windows.Forms;
 8 None.gif using  System.Runtime.InteropServices;
 9 None.gif
10 None.gif namespace  WindowsApplication1
11 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
12InBlock.gif    public partial class Form1 : Form
13ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
14InBlock.gif        [DllImport("User32.dll", EntryPoint = "FindWindow")]
15InBlock.gif        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
16InBlock.gif
17InBlock.gif        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
18InBlock.gif        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
19InBlock.gif
20InBlock.gif        [DllImport("User32.dll", EntryPoint = "SendMessage")]
21InBlock.gif        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
22InBlock.gif
23InBlock.gif        public Form1()
24ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
25InBlock.gif            InitializeComponent();
26ExpandedSubBlockEnd.gif        }

27InBlock.gif
28InBlock.gif        private void button1_Click(object sender, EventArgs e)
29ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
30InBlock.gif            const int WM_GETTEXT = 0x000D;
31InBlock.gif
32InBlock.gif            string lpszParentClass = "Form";
33InBlock.gif            string lpszParentWindow = "Form1";
34InBlock.gif            string lpszClass = "Button";
35InBlock.gif
36InBlock.gif            string getTxt = "";
37InBlock.gif            IntPtr ParenthWnd = new IntPtr(0);
38InBlock.gif            IntPtr EdithWnd = new IntPtr(0);
39InBlock.gif
40InBlock.gif            ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
41InBlock.gif            if (!ParenthWnd.Equals(IntPtr.Zero))
42ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
43InBlock.gif                EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, lpszClass, "");
44InBlock.gif                if (!EdithWnd.Equals(IntPtr.Zero))
45ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
46InBlock.gif                    SendMessage(EdithWnd, WM_GETTEXT, (IntPtr)0, getTxt);
47InBlock.gif                    if (getTxt.Length != 0)
48ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
49InBlock.gif                        MessageBox.Show(getTxt);
50ExpandedSubBlockEnd.gif                    }

51ExpandedSubBlockEnd.gif                }

52InBlock.gif
53ExpandedSubBlockEnd.gif            }

54ExpandedSubBlockEnd.gif        }

55ExpandedSubBlockEnd.gif    }

56ExpandedBlockEnd.gif}

 转:http://www.cnblogs.com/dongjie/archive/2006/12/16/594197.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值