为虚拟文件夹创建的新文件夹按钮无法在CFileDialog中显示

时间:2018-02-21 00:55:13

标签: windows mfc shell-extensions cfiledialog shell-namespace-extension

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

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

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浏览此虚拟文件夹时,我在工具栏中找不到任何“新建文件夹”按钮:

enter image description here

我可以在CFileDialog中的“Document”或C盘下看到所有其他系 如何解决这个问题?

0 个答案:

没有答案