日期:2014-05-17 浏览次数:21056 次
using System;
using System.Runtime.InteropServices;
namespace SendMsgToWindow
{
class MainClass
{
//[DllImport("USER32.DLL")]
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow (string lpClassName, string lpWindowName);
//静态方法必须在静态方法中调用?
private static void MyFindWindow (string wndName)
{
IntPtr ip = FindWindow (null, wndName);
Console.WriteLine(ip.ToString());
if (ip != IntPtr.Zero) {
//找到句柄后,你就可以做你想做的事了,发送信息你可以用SendKeys;
Console.WriteLine ("yes");
}
}
public static void Main (string[] args)
{
MyFindWindow ("test.txt - 记事本");//
}
}
}