显然,这与 win32 api - CreateDirectory() 无关。但我正在尝试托管一个 IShellView,并希望以最面向 shell 的方式来执行此操作。我原以为会有一个 createobject 或 createfolder 或来自 IShellFolder 的一些类似的东西。但是 IShellView 和 IShellFolder 甚至 IFolderView 似乎都没有这样的东西。
是否有一种 Shell 编程方式来创建新文件夹?还是我需要使用路径名创建一个文件夹,这是老式的方式?
如果我必须通过 CreateDirectory() 来完成,那么我的下一个问题可能是:关于如何让 IShellView / IFolderView 真正看到这个新对象并将其显示给用户的任何想法?
动机:创建我自己的文件对话框替换,我想提供标准 XP 样式文件对话框的“新文件夹”工具栏图标功能。
编辑:我继续使用 CreateDirectory 创建了一些基本有效的东西。但是,我仍然希望有更好的方法来做到这一点,但这样你就可以看到它是如何工作的,并提供更好的想法来更好地解决这个问题:
PidlUtils::Pidl pidl(m_folder);
CFilename folderName(GetDisplayNameOf(pidl), "New Folder");
for (int i = 2; folderName.Exists(); ++i)
folderName.SetFullName(FString("New Folder (%d)", i));
if (!CPathname::Create(folderName, false))
throw CContextException("Unable to create a new folder here: ");
// get the PIDL for the newly created folder
PidlUtils::Pidl pidlNew;
#ifdef UNICODE
const wchar_t * wszName = folderName.c_str();
#else
wchar_t wszName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, folderName.GetFullName(), -1, wszName, MAX_PATH);
#endif
m_hresult = m_folder->ParseDisplayName(NULL, NULL, wszName, NULL, pidlNew, NULL);
if (FAILED(m_hresult))
throw CLabeledException(FString("Unable to get the PIDL for the new folder: 0x%X", m_hresult));
// upgrade our interface so we can select & rename it
CComQIPtr<IShellView2> sv2(m_shell_view);
if (!sv2)
throw CLabeledException("Unable to obtain the IShellView2 we need to rename the newly created folder.");
// force it to see thew new folder
sv2->Refresh();
// select the new folder, and begin the rename process
m_hresult = sv2->SelectAndPositionItem(pidlNew, SVSI_EDIT|SVSI_DESELECTOTHERS|SVSI_ENSUREVISIBLE|SVSI_POSITIONITEM, NULL);
if (FAILED(m_hresult))
throw CLabeledException(FString("Unable to select and position the new folder item: 0x%X", m_hresult));