从 UWP 应用程序中提取图标
Extract icon from UWP application
在尝试实现"打开方式"功能时,我遇到了从UWP应用程序中提取图标的问题。因此,在收到在SHAssocEnumHandlers的帮助下打开特定文件的推荐应用程序列表后,我正在尝试在IAssocHandler::GetIconLocation和经典ExtractIcon()
的帮助下为每个应用程序提取图标。例如,对于像Paint这样的程序,一切都可以正常工作。我有 Paint 二进制文件的完整路径,可以从中提取图标。但是使用"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.
}
}
}
}
看起来我已经找到了解决方案。根据 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 FilesWindowsAppsMicrosoft.Windows.Photos_16.511.8630.0_neutral_split.scale-125_8wekyb3d8bbweAssetsPhotosAppList.scale-125.png
之后,我可以使用它来显示图标本身,没有任何问题。
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么istream不支持右值提取
- 如何设置一个范围来提取我想要获得的信息
- 视觉工作室项目.提取源文件夹名称
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 从字符串中提取整数并形成一个数组
- C ++中的StringStream有助于使用向量从字符串中提取逗号分隔的整数,而不是空格分隔的整数,为什么?
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- 从 std::vector<无符号字符>切片中提取 int?
- 在C++中使用重载提取运算符时出现问题
- 在 Qt(C++) 中使用 QProcess 解压缩 - 提取目录问题
- C++(.cpp文件和.h文件)拆分代码并添加一个函数,提取 - 这很容易吗?
- 无法从 std::string 中提取C++ Unicode 符号
- 如何为 C++ Visual Studio 2019 指定应用程序图标?
- 如何从也包含C++字母的文本文件中提取某些数字?
- 如何从适合一定范围的数字中提取数字?
- C++从通用引用中提取实际类型
- 从运行服务的应用程序代码中提取窗口句柄
- 从 UWP 应用程序中提取图标