Creating an HICON from a byte array in C++?

落爺英雄遲暮 提交于 2019-12-24 05:34:10

问题


I have a PNG-encoded icon as a byte array in memory. What is the recommended way of creating an HICON object from this byte array?


Imaginary bonus points if you know a solution without ATL or GDI+... :)


回答1:


HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, dataSize);
LPVOID pImage = GlobalLock(hMem);
memcpy(pImage, pngData, dataSize);
GlobalUnlock(hMem);

ATL::CComPtr<IStream> pStream;
CreateStreamOnHGlobal(hMem, TRUE, &pStream);

Gdiplus::Bitmap *pBitmap = new Gdiplus::Bitmap(pStream);
HICON YOUR_HICON = pBitmap->GetHICON();



回答2:


It looks like you could do this with CreateBitmap and CreateIconIndirect, or maybe even just CreateIcon. Don't ask me for code because I'm not really familiar with this low-level graphics stuff.



来源:https://stackoverflow.com/questions/1922370/creating-an-hicon-from-a-byte-array-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!