Is there a way to activate or bring a window of an external application to the front? The closest I could get was
var application = Application.Attach("SearchApp");
var searchWindow = application.GetWindows()[0];
searchWindow.Focus(DisplayState.Maximized);
but all that does is maximize it in the background if it's not currently active.
Got it working.
[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);
来源:https://stackoverflow.com/questions/24806697/is-there-any-way-to-activate-a-window-with-white