gpt4 book ai didi

c++ - WIC中调用CreateBitmapFromHIcon时指定HICON索引

转载 作者:行者123 更新时间:2023-11-28 01:16:01 25 4
gpt4 key购买 nike

根据文档 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 值分配足够的空间,因此 hiconLargehiconSmall 应该是指向 HICON 对象 (HICON *) 的指针。目前,您只有足够的空间容纳一个。然后,您可以像通常访问数组一样访问这些值。

关于c++ - WIC中调用CreateBitmapFromHIcon时指定HICON索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58686113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com