FindWindow和SetForegroundWindow的替代品?

我正在寻找使用FindWindow()SetForegroundWindow()切换到不同应用程序的旧User32.dll版本的替代品。

我确实找到了第一个使用Process.GetProcessesByName()的替代方法,但我没有看到相应的方法切换(设置活动/前台)到该应用程序。

有没有办法在不使用User32.dll方法的情况下这样做?

谢谢您的帮助。

编辑

我接受了@Sorceri的答案,虽然这不是我想要的答案。

答:没有。

但是,为了帮助下一个想要找到窗口并从C#激活它的想法者,你需要做的就是:

 [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); void ActivateApp(string processName) { Process[] p = Process.GetProcessesByName(processName); // Activate the first application we find with this name if (p.Count() > 0) SetForegroundWindow(p[0].MainWindowHandle); } 

例如,要将记事本放在前面,您可以致电:

 ActivateApp("notepad"); 

作为旁注 – 对于那些试图将应用程序中的窗口带到前台的人来说,只需调用Activate()方法即可 。

您可以使用SetActiveWindow替代SetForeGroundWindow 。 我会说你应该通过所有Windows Manipulation Api函数 ,看看是否有你遗漏的东西。

另请注意,您可以通过Process.Handle属性获取System.Diagnostics.Process对象的句柄。

SetForeGroundWindow的替代品是VisualBasic的AppActivate

像这样称呼它

 Microsoft.VisualBasic.Interaction.AppActivate("WindowTitle") 

仅仅因为它在VisualBasic命名空间中并不意味着你不能在C#中使用它。

完整文档在这里

您可以将System.Diagnostics.Process Object用于FindWindow等效项。 目前没有SetForegroundWindow的等价物。 您将需要使用Pinvoke和SetForgroundWindow。

 [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd);