Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert BITMAP to HBITMAP

If I have a BITMAP named bitmap, how to I convert this into an HBITMAP?

So far I have tried:

HBITMAP hbm = (HBITMAP)&bitmap; //doesn't work

HANDLE hand = &bitmap;
HBITMAP hbm = hand; //doesn't work

CImage cim;
cim.Attach(&bitmap);
HBITMAP hbm = cim.Detach(); //definitely doesn't work

CBitmap cbm;
cbm.Attach(bitmap);
CImage cim;
cim.Attach(cbm.Detach());
HBITMAP hbm = cbm.Detach(); //desperate I know, horribly failed

There has got to be some easy, one line way to do it but I just can't find it. Can I get some help?

like image 200
xcdemon05 Avatar asked Feb 18 '23 06:02

xcdemon05


1 Answers

Call CreateBitmapIndirect passing your BITMAP. Hey presto, an HBITMAP is returned.

For what it's worth, a good way to look for the answer yourself is to go to the MSDN topic describing BITMAP. Scroll down to the bottom of the page and look at the See Also section. The most important functions that use the type will be listed there, and indeed CreateBitmapIndirect is there. That's always a useful way of finding out what can be done with any particular Win32 type.

like image 116
David Heffernan Avatar answered Feb 20 '23 03:02

David Heffernan