什么是“Shell命名空间”方式来创建一个新的文件夹? [英] What is the "Shell Namespace" way to create a new folder?

查看:306
本文介绍了什么是“Shell命名空间”方式来创建一个新的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,这与win32 api - CreateDirectory()无关。但是我试图托管一个IShellView,并且想做这个最面向壳的方式。我想会有一个createobject或createfolder或一些从IShellFolder。但是既不是IShellView也不是IShellFolder甚至IFolderView似乎都没有这样的东西。

Obviously this is trivial to do with win32 api - CreateDirectory(). But I'm trying to host an IShellView, and would like to do this the most shell-oriented way. I would have thought that there would be a createobject or createfolder or some such from an IShellFolder. But neither IShellView nor IShellFolder nor even IFolderView seem to have anything quite like this.

有一个Shell编程的方式来创建一个新的文件夹?或者,我需要使用路径名,以老式方式创建一个文件夹?

Is there a Shell-programming way to create a new folder? Or do I need to create a folder using a pathname, the old-fashioned way?

如果我必须通过CreateDirectory(),我的下一个问题可能是:有关如何获取IShellView / IFolderView实际看到这个新对象并显示给用户的任何想法?

If I have to do it via CreateDirectory(), then my next question might be: any ideas as to how to get the IShellView / IFolderView to actually see this new object and display it to the user?

动机:创建自己的文件对话框替换和我想要提供标准XP风格文件对话框的新文件夹工具栏图标功能。

Motivation: Creating my own File Dialog replacement and I want to provide the "new folder" toolbar icon functionality of the standard XP-style file dialog.

编辑:我继续使用CreateDirectory创建了基本上可以工作的东西。但是,我仍然希望有一个更好的方法来做到这一点,但是,这样你就可以看到它是如何工作,并提供更好的想法,以更好地解决这个问题:

I went ahead and created something that basically works, using CreateDirectory. However, I'm still hoping that there's a better way to do this, but so that you can see how that works, and to offer better ideas as to solve this issue better:

    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));


推荐答案

Shell文件夹通常实现IStorage接口,很简单。例如,以下在桌面上创建一个名为abcd的文件夹:

Shell folders usually implement the IStorage interface, so this is pretty simple. For example, the following creates a folder named "abcd" on the desktop:

  CComPtr<IShellFolder> pDesktop;
  HRESULT hr = SHGetDesktopFolder(&pDesktop);
  if (FAILED(hr)) return;
  CComQIPtr<IStorage> pStorage(pDesktop);
  if (!pStorage) return;
  CComPtr<IStorage> dummy;
  hr = pStorage->CreateStorage(L"abcd", STGM_FAILIFTHERE, 0, 0, &dummy);

这篇关于什么是“Shell命名空间”方式来创建一个新的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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