如何打开文件夹C ++ [英] How to open folder with C++

查看:335
本文介绍了如何打开文件夹C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开出一个特定的文件夹资源管理器窗口,可以说C:\\\\ Windows的我应该使用什么功能,达到我的目标?我使用的是Windows,以便可以使用API​​,还我可以使用提升,但我不能使用C ++ 11。

I need to open an explorer window showing a specific folder, lets say "C:\\Windows" What function should I use to reach my goal? I'm using Windows so can use API, also I can use boost, but I can't use C++11.

推荐答案

您可以使用 SHOpenFolderAndSelectItems 函数来做到这一点,而不是强行运行资源管理器自己(如果该用户已经取代资源管理器作为默认的文件管理器,例如?)。

You can use the SHOpenFolderAndSelectItems function to do this, rather than forcibly running Explorer yourself (what if the user has replaced Explorer as their default file manager, for example?).

LPCWSTR pszPathToOpen = L"C:\\Windows";
PIDLIST_ABSOLUTE pidl;
if (SUCCEEDED(SHParseDisplayName(pszPathToOpen, 0, &pidl, 0, 0)))
{
    // we don't want to actually select anything in the folder, so we pass an empty
    // PIDL in the array. if you want to select one or more items in the opened
    // folder you'd need to build the PIDL array appropriately
    ITEMIDLIST idNull = { 0 };
    LPCITEMIDLIST pidlNull[1] = { &idNull };
    SHOpenFolderAndSelectItems(pidl, 1, pidlNull, 0);
    ILFree(pidl);
}

另外,你可以叫的ShellExecute 文件夹直接运行其默认操作(这通常是在浏览器窗口中打开):

Alternatively, you can call ShellExecute on the folder directly to run its default action (which is normally to open in a browser window):

ShellExecute(NULL, NULL, L"C:\\Windows", NULL, NULL, SW_SHOWNORMAL);

这篇关于如何打开文件夹C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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