通过使用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中的“Document”或C盘下看到所有其他系 如何解决这个问题?