3

明らかに、これは 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));
4

3 に答える 3

3

はい、IContextMenuを取得してサブ メニューを探すことができますが、わざわざCreateDirectory を呼び出した後でSHChangeNotifyを呼び出すだけです。

于 2009-11-20T22:36:21.543 に答える
1

シェルフォルダは通常IStorageインターフェイスを実装しているため、これは非常に簡単です。たとえば、次の例では、デスクトップに「abcd」という名前のフォルダが作成されます。

  CComPtr <IShellFolder> pDesktop;
  HRESULT hr = SHGetDesktopFolder(&pDesktop);
  if(FAILED(hr))return;
  CComQIPtr <IStorage> pStorage(pDesktop);
  if(!pStorage)return;
  CComPtr<IStorage>ダミー;
  hr = pStorage-> CreateStorage(L "abcd"、STGM_FAILIFTHERE、0、0、&dummy);
于 2009-12-25T18:01:26.967 に答える
0

Win32API関数のCreateDirectoryは「正しい方法」のようです。少なくとも、私はこれ以上良いものを見つけることができません-そしてここでの答えはそれを行うためのより良い方法に実際に光を当てることはありません。

于 2009-12-01T19:19:05.550 に答える