有没有办法激活白色窗口?

时间:2014-07-17 14:46:06

标签: c# wpf windows automation white

有没有办法激活或将外部应用程序的窗口带到前面?我能得到的最接近的是

var application = Application.Attach("SearchApp");
var searchWindow = application.GetWindows()[0];

searchWindow.Focus(DisplayState.Maximized);

但所有这一切都是在后台最大化它,如果它当前不活跃。

1 个答案:

答案 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);