我正在开发 IFileOpenDialog
和 IFileSaveDialog
的替代品。
我几乎让它工作(至少 IFileOpenDialog
),但是当我想返回代表新文件名(用户选择保存在GetResult()
方法),我无法让 SHParseDisplayName
使用这个新文件名。我总是收到错误 “系统找不到指定的文件”
。
我会感谢一些示例或其他解决方案来解决我的问题。
编辑:
HRESULT CFileSaveDialogProxy::GetResult( __RPC__deref_out_opt IShellItem **ppsi)
{
//return m_Original->GetResult(ppsi);
WCHAR pszPath[MAX_PATH] = {0};
HRESULT hr = ERROR_CANCELLED;
if (m_SelectedFiles.size() > 0)
{
QString s = m_SelectedFiles.at(0);
s.replace(QString("/"),QString("\\"));
s.toWCharArray(pszPath);
//PCIDLIST_ABSOLUTE pIdL = ILCreateFromPath(pszPath);
PIDLIST_ABSOLUTE pIdL = NULL;
SFGAOF out;
hr = SHParseDisplayName(pszPath,NULL,&pIdL,SFGAO_FILESYSTEM,&out);
if (SUCCEEDED(hr))
{
hr = SHCreateItemFromIDList(pIdL, IID_PPV_ARGS(ppsi));
}
}
return hr;
}
最佳答案
您必须使用 IBindCtx
参数将附加数据传递给解析器,在这种情况下是您自己的文件元数据,因此 SHParseDisplayName()
不会尝试访问真实的文件以获取元数据。这在 IShellFolder::ParseDisplayName()
中有描述。和 SHCreateItemFromParsingName()
文档:
A pointer to a bind context used to pass parameters as inputs and outputs to the parsing function. These passed parameters are often specific to the data source and are documented by the data source owners. For example, the file system data source accepts the name being parsed (as a WIN32_FIND_DATA structure), using the STR_FILE_SYS_BIND_DATA bind context parameter. STR_PARSE_PREFER_FOLDER_BROWSING can be passed to indicate that URLs are parsed using the file system data source when possible. Construct a bind context object using CreateBindCtx and populate the values using IBindCtx::RegisterObjectParam. See Bind Context String Keys for a complete list of these.
并在 MSDN“Old New Thing”博客上进行了详细概述:
Creating a simple pidl: For the times you care enough to send the very fake 🕗
关于c++ - 路径不存在时的 SHParseDisplayName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18576103/