S
Habe jetzt funktionierenden sample code gefunden.
HBITMAP ConvertIconToBitmap(HICON hicon)
{
IWICImagingFactory* pFactory;
IWICBitmap* pBitmap;
IWICFormatConverter* pConverter;
HBITMAP ret = NULL;
if (SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL,
CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (void**)&pFactory)))
{
if (SUCCEEDED(pFactory->CreateBitmapFromHICON(hicon, &pBitmap)))
{
if (SUCCEEDED(pFactory->CreateFormatConverter(&pConverter)))
{
UINT cx, cy;
PBYTE pbBits;
HBITMAP hbmp;
if (SUCCEEDED(pConverter->Initialize(pBitmap, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeCustom)) && SUCCEEDED(
pConverter->GetSize(&cx, &cy)) && NULL != (hbmp = Create32BitHBITMAP(cx, cy, &pbBits)))
{
UINT cbStride = cx * sizeof(UINT32);
UINT cbBitmap = cy * cbStride;
if (SUCCEEDED(pConverter->CopyPixels(NULL, cbStride, cbBitmap, pbBits)))
ret = hbmp;
else
DeleteObject(hbmp);
}
pConverter->Release();
}
pBitmap->Release();
}
pFactory->Release();
}
return ret;
}