windows 在资源管理器中打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/354902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open in Explorer
提问by Lodle
How do you open a path in explorer by code in c++. I googled and couldn't find any thing but systems commands to do this, however, i dont want it to block or show the console window.
你如何通过 C++ 中的代码在资源管理器中打开路径。我用谷歌搜索,除了系统命令之外找不到任何东西来执行此操作,但是,我不希望它阻止或显示控制台窗口。
回答by
You probably are looking for the ShellExecute()function in shell32.h. It is called with an "action verb", a path, and optional parameters. In your case this will want either "open" or "explore" as follows:
您可能正在shell32.h中寻找ShellExecute()函数。使用“动作动词”、路径和可选参数调用它。在您的情况下,这将需要“打开”或“探索”,如下所示:
ShellExecute(NULL, "open", "C:\", NULL, NULL, SW_SHOWDEFAULT);
This will open an unattached explorer window at C:. ShellExecute() will give basically the same action as typing in a command at the Run dialog. It will also handle URLs, so the following will open up the user's default browser:
这将在 C: 处打开一个独立的资源管理器窗口。ShellExecute() 将提供与在“运行”对话框中键入命令基本相同的操作。它还将处理 URL,因此以下内容将打开用户的默认浏览器:
ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWDEFAULT);
Although make sure to pay attention to the note in the documentation that ShellExecute relies on COM (Although your code doesn't have to worry about any COM objects itself).
虽然一定要注意文档中的注释,ShellExecute 依赖于 COM(尽管您的代码不必担心任何 COM 对象本身)。
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
回答by berlindev
This does not show the command window, just opens the directory.
这不会显示命令窗口,只是打开目录。
system("explorer C:\");