How do I detect if Windows Explorer is displaying

2019-06-10 00:28发布

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?

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

2条回答
做自己的国王
2楼-- · 2019-06-10 00:42

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.

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

查看更多
乱世女痞
3楼-- · 2019-06-10 00:44

Try this:

ShellExecute(NULL, _T("Open"), _T(m_strOutputPath), NULL, NULL, SW_SHOWDEFAULT);
查看更多
登录 后发表回答