简体   繁体   English

在资源管理器中打开

[英]Open in Explorer

How do you open a path in explorer by code in c++.你如何通过 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.我用谷歌搜索,除了系统命令之外找不到任何东西来执行此操作,但是,我不希望它阻止或显示控制台窗口。

You probably are looking for the ShellExecute() function in shell32.h.您可能正在 shell32.h 中寻找ShellExecute()函数。 It is called with an "action verb", a path, and optional parameters.它使用“动作动词”、路径和可选参数来调用。 In your case this will want either "open" or "explore" as follows:在您的情况下,这将需要“打开”或“探索”,如下所示:

ShellExecute(NULL, "open", "C:\", NULL, NULL, SW_SHOWDEFAULT);

This will open an unattached explorer window at C:.这将在 C: 处打开一个独立的资源管理器窗口。 ShellExecute() will give basically the same action as typing in a command at the Run dialog. ShellExecute() 将提供与在运行对话框中键入命令基本相同的操作。 It will also handle URLs, so the following will open up the user's default browser:它还将处理 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)

这不会显示命令窗口,只是打开目录。


system("explorer C:\\");

I'm now using VS2017, using as follows works:我现在使用VS2017,使用如下工作:

ShellExecute(NULL, L"open", L"YourFolderPath\\YourFile.xxx", NULL, NULL, SW_RESTORE);

also reference ShellExecute to open an .exe in C++还引用ShellExecute 在 C++ 中打开一个 .exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM