明らかに、これは win32 api - CreateDirectory() で行うのは簡単です。しかし、私は IShellView をホストしようとしており、これを最もシェル指向の方法で行いたいと考えています。IShellFolder から createobject や createfolder などがあると思っていたでしょう。しかし、IShellView も IShellFolder も IFolderView も、このようなものを持っているようには見えません。
新しいフォルダーを作成するシェル プログラミングの方法はありますか? それとも、昔ながらの方法でパス名を使用してフォルダーを作成する必要がありますか?
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));