How can I create a device context compatible bitmap and then associating the obtained handle to a BITMAP struct? If I write:
...
HBITMAP hbitmap = CreateCompatibleBitmap(hdc, width, height); // these three arguments are initialized somewhere else
hbitmap = CreateBitmapIndirect(bitmap); // argument already initialized and properly filled
...
A HBITMAP handle compatible with hdc is created, and then a new HBITMAP (filled with bitmap data) is initialized, though without keeping its compatibility. Is there a function which allows not to create a HBITMAP from a BITMAP, but rather fills an initialized HBITMAP with an already existing BITMAP source?
CreateBitmapIndirect
takesBITMAP
on its input. And you can get it viaGetObject
fromHBITMAP
:CreateBitmapIndirect
will be able create a bitmap from this struct. Or you can useCreateCompatibleBitmap
to create compatible bitmap providing width/height from obtainedBitmap
.