Dim*_*ich 0 c++ winapi icons uwp
在尝试实现"打开方式"功能时,我遇到了从UWP应用程序中提取图标的问题.因此,在收到推荐的应用程序列表以便在SHAssocEnumHandlers的帮助下打开特定文件之后,我试图在IAssocHandler :: GetIconLocation和classic的帮助下为每个应用程序提取图标ExtractIcon().例如,像Paint这样的程序一切正常.我有绘制二进制文件的完整路径,可以从中提取图标.但是对于像"3D builder","Photos"和其他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.
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
看起来我找到了解决方案.根据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之后我可以用它来显示没有任何问题的图标本身.
| 归档时间: |
|
| 查看次数: |
1395 次 |
| 最近记录: |