摘要:说来说去,还是觉得API的功能是最强大的,但是.NET FCL,MFC等对API的封装之后也使得程序的开发变得更加容易。本模块的主要原理还是使用API,查找指定类型,窗口文本的窗口对象,获取该对象的指针。然后操作该对象。
实例1:
创建一个C#Windows Form应用程序,向窗口中添加一个按钮button1,添加事件相应函数:
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("This is button1 click!");
}
实例2:
创建一个C# Windows Form应用程序,添加一个按钮控件button1
1:添加using System.Runtime.InteropServices;
2: 添加对API的引用:
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,string lpszWindow);
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
public static extern IntP