Question about HBITMAP


Hi !

I have a question -

for example, I create Windows - bitmap using my own method-
first, I’m calculate bytes count, call operator new BYTE [image_bytes_count];

Can I later create Windows bitmap and give HBITMAP using my bitmap memory (earlier allocated),
without needed to Windows allocate new memory for bitmap (say, I’m need convert
my bitmap bytes to HBITMAP handle).


Not really. Windows GDI wants to “own” the memory for an HBITMAP. You could call CreateBitmap() and provide the pixels to initialize the bitmap with, but it sounds like this is not what you want. The closest you can get is to first call Windows and create a DibSection:

HBITMAP CreateDIBSection( __in HDC hdc, __in const BITMAPINFO *pbmi, __in UINT iUsage, __out VOID **ppvBits, __in HANDLE hSection, __in DWORD dwOffset );

And then use the pointer returned in *ppvBits to compose your image. The resulting HBITMAP can then be used in subsequent calls to BitBlt, et. al.