[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
我的窗体是无边框风格,我以为只要设置了其Text属性,FindWindow就没问题,但运行发现不行。通过类名吗?我的窗体运行中需要创建很多个,每一个单独设置一个窗口类?如果FindWindow不行,还有哪些进程间通信的方法,小弟用来传递的数据极小,只求速度越快越好。求各位给一个办法,谢谢!
2.使用Process对象的MainWindowHandle获取该进程的主窗口句柄。
3.使用SendMessage函数给该窗口发消息。只是设想,未经验证。
如果你能获得进程ID的话,也可以使用GetProcessById
{
if (Path.GetFileNameWithoutExtension(p.StartInfo.FileName) == "你说的文件名")
{
Console.WriteLine(p.MainWindowHandle.ToInt32());
}
}