如何检测Windows资源管理器是否正在显示给定文件夹? [英] How do I detect if Windows Explorer is displaying a given folder?

查看:118
本文介绍了如何检测Windows资源管理器是否正在显示给定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序在可执行文件的目录中创建一个文件夹,并保存一些输出文件.应用程序完成后,我可以使用ShellExecute(NULL, _T("Open"), _T("Explorer"), _T(m_strOutputPath), NULL, SW_SHOWDEFAULT);

My program creates a folder in the executable's directory and saves some output files. When the application finishes, I have it automatically open the folder in an explorer window using ShellExecute(NULL, _T("Open"), _T("Explorer"), _T(m_strOutputPath), NULL, SW_SHOWDEFAULT);

现在,如果我继续重新运行该程序,即使它已经打开,它也将继续打开同一文件夹.对于没有头脑的用户(我是其中之一),这将导致同一文件夹的多个窗口.

Now, if I keep re-running the program, it will just keep opening the same folder even if it is already opened. For the absent-minded user (with me being one of them), this results in multiple windows of the same folder.

有没有一种方法可以检测该文件夹是否已在资源管理器窗口中打开,而不是使该文件夹打开一个新窗口(如果已打开)?

Is there a way to detect if the folder is already opened in an explorer window and not make it open a new window if it is already opened?

我正在Windows Vista上的MSVS 2008 SP1中进行开发,但是该程序将在XP,Vista和7上运行.

I'm developing in MSVS 2008 SP1 on Windows Vista, but the program will run on XP, Vista, and 7.

推荐答案

您可以使用

You can use the SHOpenFolderAndSelectItems function. It will open a folder window and select the files given. If the window is already open, it'll bring it to the front.

在内部,它使用 IShellWindows 接口,特别是FindWindowSW方法.

Internally, it uses the IShellWindows interface, specifically the FindWindowSW method.

这篇关于如何检测Windows资源管理器是否正在显示给定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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