2

通过使用 shell 命名空间扩展,我创建了一个虚拟文件夹并在工具栏上添加了一个“新建文件夹”按钮,当我使用 Windows 资源管理器打开它时,我可以看到该按钮: 在此处输入图像描述

“新建文件夹”按钮的相关代码很简单:

class CFolderViewCommandProvider : public IExplorerCommandProvider
{
public:
// IUnknown
IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv)
{
    static const QITAB qit[] =
    {
        QITABENT(CFolderViewCommandProvider, IExplorerCommandProvider),
        { 0 },
    };
    return QISearch(this, qit, riid, ppv);
}

IFACEMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&_cRef); }
IFACEMETHODIMP_(ULONG) Release()
{
    long cRef = InterlockedDecrement(&_cRef);
    if (!cRef)
    {
        delete this;
    }
    return cRef;
}
    // IExplorerCommandProvider
IFACEMETHODIMP GetCommands(IUnknown *punkSite, REFIID riid, void **ppv);
IFACEMETHODIMP GetCommand(REFGUID /* rguidCommandId */, REFIID /* riid */, void **ppv)
    { *ppv = NULL; return E_NOTIMPL; }

CFolderViewCommandProvider() : _cRef(1)
{
}

private:
static HRESULT s_NewFolder(IShellItemArray *psiItemArray, IUnknown *pv);
.
.
.

const FVCOMMANDITEM CFolderViewCommandProvider::c_FVTasks[] =
{

{ &GUID_Settings, IDS_SETTINGS, IDS_SETTINGS, L"shell32.dll,-16710", 0, CFolderViewCommandProvider::s_NewFolder, NULL, 0 }
};

IFACEMETHODIMP CFolderViewCommandProvider::GetCommands(IUnknown * /* punkSite */, REFIID riid, void ** ppv)
{
*ppv = NULL;
CFolderViewCommandEnumerator *pFVCommandEnum = new (std::nothrow) CFolderViewCommandEnumerator(c_FVTasks, ARRAYSIZE(c_FVTasks));
HRESULT hr = pFVCommandEnum ? S_OK : E_OUTOFMEMORY;
if (SUCCEEDED(hr))
{
    hr = pFVCommandEnum->QueryInterface(riid, ppv);
    pFVCommandEnum->Release();
}
return S_OK;
}
IFACEMETHODIMP CFolderViewCommand::Invoke(IShellItemArray *psiItemArray, IBindCtx *pbc)
{
HRESULT hr = S_OK; // If no function defined - just return S_OK
if (_pfvci && _pfvci->pfnInvoke)
{
    hr = _pfvci->pfnInvoke(psiItemArray, pbc);
}
return hr;
}
.
.
.

“新建文件夹”按钮只是在单击时弹出一个消息框。但是当我CFileDialog用来浏览这个虚拟文件夹时,我在工具栏中找不到任何“新建文件夹”按钮:

在此处输入图像描述

我可以在 CFileDialog 中的“文档”或 C 驱动器下看到所有其他系统文件夹的“新建文件夹”按钮,但是当我在 CFileDialog 中打开虚拟文件夹时,虚拟文件​​夹的“新建文件夹”按钮会消失。如何解决这个问题?

4

0 回答 0