windows - 从图标处理程序外壳扩展中的资源加载位图图标
问题描述
我需要.bmp
从资源中加载一个图标IExtractIcon::Extract
,但我无法弄清楚它为什么不起作用。我不断得到一个黑色或白色的矩形图标应该是。
我在项目资源.rc
文件中声明了两个图标:ICON_16_BITMAP
和ICON_BITMAP
. 绝对应该加载图标,因为它们在LoadImageW
.
// IExtractIcon
HRESULT icon_handler::GetIconLocation(UINT u_flags, PWSTR psz_icon_file, UINT cch_max, int* pi_index, UINT* pw_flags)
{
*pw_flags = GIL_NOTFILENAME | GIL_DONTCACHE;
return S_OK;
}
extern HINSTANCE global_h_instance;
HRESULT icon_handler::Extract(PCWSTR psz_file, UINT n_icon_index, HICON* phicon_large, HICON* phicon_small, UINT n_icon_size)
{
const int small_size = HIWORD(n_icon_size);
const int large_size = LOWORD(n_icon_size);
if (phicon_large != nullptr)
{
OutputDebugStringW((L"Extract large icon: " + std::to_wstring(large_size)).c_str());
*phicon_large = HICON(LoadImageW(global_h_instance, MAKEINTRESOURCE(ICON_BITMAP), IMAGE_BITMAP, large_size, large_size,
LR_SHARED));
}
if (phicon_small != nullptr)
{
OutputDebugStringW((L"Extract small icon: " + std::to_wstring(small_size)).c_str());
*phicon_small = HICON(LoadImageW(global_h_instance, MAKEINTRESOURCE(ICON_16_BITMAP), IMAGE_BITMAP, small_size, small_size,
LR_SHARED));
}
return S_OK;
}
我尝试过很多教程,但这似乎很简单,我可以去,但到目前为止还没有成功。有什么突出的地方可能是图标不起作用的原因吗?
解决方案
BMP 与图标格式不一样。
它不能被 HICON 强制转换。
最简单的方法是通过转换图片工具将BMP文件转换成图标文件,然后加载到资源中。
推荐阅读
- view - Rails 5.2.3 content_for 未按规定工作
- python - 如何为单个记录器使用多种格式
- loops - 由于可能不正确的比较,无法在 Assembly 中输入 for 循环
- c - 使用结构读取 PGM 文件
- javascript - 如何修复无法读取未定义的属性“纬度”
- laravel-dusk - 如何在 Laravel Dusk 浏览器测试、单元测试和功能测试之间共享代码
- python - 由于某种原因,我无法显示此文件
- performance - 优化 GPU 利用率处理离散图像的技术
- sql-server - 如何知道 SQL Server 何时升级?
- python - 将 django rest auth 与 django allauth 集成