c++ - 在 WIC 中调用 CreateBitmapFromHIcon 时指定 HICON 索引
问题描述
根据文档,ExtractIconEx返回一个指向 HICON 数组的指针。在传递给CreateBitmapFromHICON时,如何指定要使用此数组中的哪个项目。
#include <iostream>
#include <Windows.h>
#include <Wincodec.h>
#pragma comment(lib,"Windowscodecs.lib")
HICON hiconLarge = NULL;
HICON hiconSmall = NULL;
int main()
{
CoInitialize(NULL);
double x, y;
IWICImagingFactory* piFactory = NULL;
IWICBitmap* piBitmap = NULL;
//Create the COM imaging factory.
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&piFactory);
UINT nIcons;
nIcons = ExtractIconEx(L"c:\\windows\\system32\\shell32.dll",
-1,
NULL,
NULL,
0);
ExtractIconEx(L"c:\\windows\\system32\\shell32.dll",
0,
&hiconLarge,
&hiconSmall,
nIcons);
std::cout << nIcons << " icons found." << std::endl;
HRESULT hResult = piFactory->CreateBitmapFromHICON(hiconLarge, &piBitmap);
if (hResult == S_OK)
{
piBitmap->GetResolution(&x, &y);
std::cout << "Resolution x=" << x << " y=" << y << std::endl;
}
}
解决方案
nIcons
HICON
在第二次调用 之前,您需要为值分配足够的空间,ExtractIconEx
因此应该是指向 HICON 对象 ( ) 的指针。目前你只有一个足够的空间。然后,您可以像通常使用数组一样访问这些值。hiconLarge
hiconSmall
HICON *
推荐阅读
- docker - 简单的 Docker 命令在 Windows 10 上不起作用
- python - Python 如果不是真的不工作
- javascript - Javascript:如何从另一个导入的模块中访问导入的模块变量?
- ssl-certificate - 证书处于活动状态,但负载均衡器在浏览器中仍显示为不安全连接
- javascript - UnhandledPromiseRejectionWarning:在将标头发送到客户端后无法设置标头(已关闭)
- php - 提高 PHP 性能:PHP $_SESSION v mysqli($servername, $username, $password, $dbname)
- javascript - 使用 jQuery 和 bootstrap-datetimepicker 获取两个日期,但它们之间的日差错误
- python - 计算python整数列表中最长的重复数字
- javascript - 对 API 数据使用 indexOf() 会受到我的变量中字符串顺序的影响
- c - 在 Ubuntu 中使用 CLION 未定义对 SDL2 函数的引用