有没有办法激活或将外部应用程序的窗口带到前面?我能得到的最接近的是
var application = Application.Attach("SearchApp");
var searchWindow = application.GetWindows()[0];
searchWindow.Focus(DisplayState.Maximized);
但所有这一切都是在后台最大化它,如果它当前不活跃。
答案 0 :(得分:2)
搞定了。
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetForegroundWindow(IntPtr windowHandle);
public bool SearchTest(string file) {
try
{
// White stuff, not relevant to problem
//var application = Application.Attach("SearchApp");
//var searchWindow = application.GetWindows()[0];
Process p = Process.GetProcessesByName("SearchApp")[0];
SetForegroundWindow(p.MainWindowHandle);