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?
CreateBitmapIndirecttakesBITMAPon its input. And you can get it viaGetObjectfromHBITMAP:CreateBitmapIndirectwill be able create a bitmap from this struct. Or you can useCreateCompatibleBitmapto create compatible bitmap providing width/height from obtainedBitmap.