Evidemment c'est trivial à faire avec win32 api - CreateDirectory(). Mais j'essaie d'héberger un IShellView, et j'aimerais le faire de la manière la plus shell-orientée. J'aurais pensé qu'il y aurait un createobject ou un createfolder ou un tel dans un IShellFolder. Mais ni IShellView ni IShellFolder, ni même IFolderView ne semblent avoir quelque chose comme ça.Quel est le moyen de "Shell Namespace" pour créer un nouveau dossier?
Existe-t-il un moyen de programmation Shell pour créer un nouveau dossier? Ou ai-je besoin de créer un dossier en utilisant un chemin, à l'ancienne?
Si je dois le faire via CreateDirectory(), alors ma question suivante pourrait être: des idées sur la façon d'obtenir l'IShellView/IFolderView pour voir réellement ce nouvel objet et l'afficher à l'utilisateur? Motivation: Création de mon propre remplacement de boîte de dialogue de fichier et je souhaite fournir la fonctionnalité d'icône de la barre d'outils «nouveau dossier» de la boîte de dialogue de fichier XP standard.
EDIT: Je suis allé de l'avant et créé quelque chose qui fonctionne essentiellement, en utilisant CreateDirectory. Cependant, j'espère encore qu'il ya une meilleure façon de le faire, mais pour que vous puissiez voir comment cela fonctionne, et d'offrir de meilleures idées pour résoudre ce problème mieux:
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));
Merci! Devoir mélanger COM et Win32 pour accomplir cela semblait bizarre. Bien sûr, cette façon d'utiliser COM Shell peut très bien se terminer par un appel à "CreateDirectory()"! lol;) – Mordachai