在WIC中调用CreateBitmapFromHIcon时指定HICON索引
Specify HICON index when calling CreateBitmapFromHIcon in WIC
根据文档,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;
}
}
在第二次调用ExtractIconEx
之前,需要为nIcons
和HICON
值分配足够的空间,因此hiconLarge
和hiconSmall
应该是指向HICON对象(HICON *
(的指针。目前您只有足够的空间放置一个。然后,您可以像通常使用数组一样访问这些值。
相关文章:
- 数组索引的值没有增加
- 芬威克树(BIT).找到具有给定累积频率的最小索引,单位为 O(logN)
- 查找最接近的大于当前数字的数字的索引
- 在C++中调整向量中的索引
- 重载元组索引运算符-C++
- 给定一个向量,如何找到该向量的所有子集和的原始索引
- 为std::string的某个索引赋值
- 并行用于C++17中数组索引范围内的循环
- 跟随整数索引列表的自定义类迭代器
- 如何在for循环中包含两个索引值的测试条件
- D3D11-将混合权重和索引传递到顶点着色器
- 将转换字符键入 int 以用作向量C++的索引
- 在 C++ 中访问数组负索引处的内存不会返回垃圾
- 如何为圆环创建索引
- 在子集化后将包含索引号的列表列表映射到标准索引序列
- 查找字符在两个索引之间出现的次数
- Azure Kinect 使用正文索引映射裁剪正文
- 如何查找哪个类对象位于数组的特定索引上(多态性)
- 数组索引重载错误
- 在WIC中调用CreateBitmapFromHIcon时指定HICON索引