如何检查是否另一个应用程序的窗口是我的机器上打开(即通过所有打开的窗口迭代)? [英] How do check if another application window is open on my machine (i.e., iterate through all open windows)?

查看:117
本文介绍了如何检查是否另一个应用程序的窗口是我的机器上打开(即通过所有打开的窗口迭代)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有写了一系列的文本文件到一个文件夹在用户的机器上的应用程序。然后,它会提示他们,如果他们想打开查看所有文件的文件夹。我使用System.Diagnostics.Process.Start()来做到这一点,它工作得很好。但是,如果已经有与文件夹打开一个窗口,我只是想重用窗口,而不是打开另一个之一。 。有助于保持整洁

I have an app that writes a series of text files to a folder on the user's machine. It then prompts them if they would like to open the folder to view all the files. I use System.Diagnostics.Process.Start() to do this and it works well. However, if there is already a window with that folder open, I would just like to reuse that window instead of opening another one. Helps keep things tidy.

任何想法

更新:这个我试过

        if (MessageBox.Show("Compiled!  Open folder?", "Compile Done", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
        {
            ProcessStartInfo Info = new ProcessStartInfo("explorer", Path);
            Info.UseShellExecute = false;

            Process.Start(Info);
        }



但它仍然会打开一个新窗口。我也试着设置UseShellExecute为真,我得到一个新的窗口,对外开放的相同的结果。

But it still opens a new window. I also tried setting UseShellExecute to true and I get the same result of a new window opening up.

推荐答案

只是尝试这样在Windows XP:

Just tried this on Windows XP:

System.Diagnostics.Process.Start(@"C:\Dev");
System.Threading.Thread.Sleep(10000);
System.Diagnostics.Process.Start(@"C:\Dev");

和它打开了我的C:\Dev文件夹中。然后,我专注于其他。 10秒后,在C:\Dev窗口闪蒸并再次突出显示。所以,你在做什么不同的地方的的工作吗?

And it opened my C:\Dev folder. I then focused elsewhere. After 10 seconds, the C:\Dev window flashed and was highlighted again. So what are you doing different where it isn't working?

(试图找出是否有显示特定的文件夹打开的窗口充满而且容易出错。我不会推荐它)

(Trying to find out if there's an open window displaying a particular folder is fraught and error prone. I wouldn't recommend it)

这篇关于如何检查是否另一个应用程序的窗口是我的机器上打开(即通过所有打开的窗口迭代)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆