在尝试实现"Open“功能时,我遇到了从UWP应用程序中提取图标时遇到的问题。因此,在收到了在SHAssocEnumHandlers帮助下打开特定文件的推荐应用程序列表之后,我试图通过IAssocHandler::GetIconLocation和经典的ExtractIcon()来提取每个应用程序的图标。例如,像油漆这样的程序,一切都很好。我有绘制二进制文件的完整路径,并可以从中提取图标。但是,有了像"3D构建器“、”照片“和其他UWP应用程序这样的应用程序,图标位置看起来就像@{Microsoft.Windows.Photos_16.511.8630.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.Windows.Photos/Files/Assets/PhotosAppList.png}。我尝试了几个不同的API来提取图标,每次都收到FILE_NOT_FOUND错误。那么,在这种情况下,谁能给我一个提示,哪个函数可以用来提取图标呢?
更新添加了部分源代码以澄清情况:
// m_handlers is a member of type std::vector<CComPtr<IAssocHandler>>
HRESULT FileManager::GetAssocHandlers(const std::wstring& strFileExtension, ASSOC_FILTER filter)
{
HRESULT hr = S_OK;
CComPtr<IEnumAssocHandlers> enumerator;
m_handlers.clear();
hr = SHAssocEnumHandlers(strFileExtension.c_str(), filter, &enumerator);
if (SUCCEEDED(hr))
{
for (CComPtr<IAssocHandler> handler;
enumerator->Next(1, &handler, nullptr) == S_OK;
handler.Release())
{
m_handlers.push_back(handler);
}
}
return hr;
}
HRESULT FileManager::GetAssociatedPrograms(BSTR bstrFileName, BSTR* bstrRet)
{
...
hr = GetAssocHandlers(strFileExtension, ASSOC_FILTER_RECOMMENDED);
if (SUCCEEDED(hr))
{
...
for (auto& handler : m_handlers)
{
...
if (SUCCEEDED(handler->GetIconLocation(&tmpStr, &resourceIndex)))
{
// And this is where I get classic full file path to regular
// applications like "MS Paint" or this weird path mentioned
// above for "Photos" UWP application for example which can't
// be used in regular ExtractIcon functions.
}
}
}
}发布于 2016-05-25 09:07:50
看来我找到了解决办法。根据MSDN,为UWP应用程序提供的图标位置路径称为“间接字符串”。我们可以将这个间接字符串传递给SHLoadIndirectString函数,并将接收到图标PNG文件的常规完整路径。在我的例子中,在将@{Microsoft.Windows.Photos_16.511.8630.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.Windows.Photos/Files/Assets/PhotosAppList.png}传递给SHLoadIndirectString()之后,我收到了类似于这样的路径:C:\Program Files\WindowsApps\Microsoft.Windows.Photos_16.511.8630.0_neutral_split.scale-125_8wekyb3d8bbwe\Assets\PhotosAppList.scale-125.png,然后我可以使用它来显示图标本身,w/o,任何问题。
https://stackoverflow.com/questions/37417757
复制相似问题