Page 1 of 1

Getting a HBITMAP for use in SetBitmap()

Posted: 2008-01-19T09:58:28-07:00
by Bob-O-Rama
Hi,

I'm not a huge fan of VC++, but when given lemons... so perhaps I'm missing some really simple way to do what I need. I have a CDialog based application and need to set the bitmap of a control. Simple enough.

I have found several difficult, and a couple totally perplexing ways to get a "MFC happy" HBITMAP from a Magick++ Image object. The one that seems to work ( and that I can understand ) is creating a new CBitmap and looping through each pixel, assigning them as we go, but this seems terribly inefficient.

Is there some uber simple way to do this that I've missed?

Thanks for suffering my stooopid question...

-- Bob

Re: Getting a HBITMAP for use in SetBitmap()

Posted: 2008-01-19T12:57:52-07:00
by el_supremo
I don't know if this'll help you, but the only thing I've seen in the IM code related to HBITMAP is in nt-feature.c:
void *ImageToHBITMAP(Image *image)

If you have access to this call and can give it an Image pointer, the (void *) that it returns is actually an HBITMAP handle.
I don't know what sort of cleanup is required. Perhaps a Magickian can clarify.

Pete

Re: Getting a HBITMAP for use in SetBitmap()

Posted: 2008-01-19T20:48:29-07:00
by Bob-O-Rama
Of course its exactly what I need. But I could not get it working. Once I got the function to complete, any attempts to use the returned handle caused it to exploded deep in the bowels of GDI. So perhaps I need a tutorial on how to use it, or confirmation that it is supposed to work and not just a vestigial tail. I'll look at the rest of the Magick corpus tomorrow, perhaps there is some other part that uses it and I can crib the proper incantation. So any assistance from those in the know is still appreciated.

-- Bob

Re: Getting a HBITMAP for use in SetBitmap()

Posted: 2008-01-27T17:59:11-07:00
by Bob-O-Rama
For posterity, an update: I ended up writing out a pre-scaled version of the image to a temp file, using CImage ( the MS provided class ) and loading the temp file into it. This gives a HBITMAP for use in SetBitmap() on a CStatic that displays the image. I wanted to implement a CRectTracker to allow the user to select a region of the image, but that was painful. Instead I just created another CStatic, a child of the one displaying the image, and made it transparent, movable, resizable. This gives a reasonable CRectTracker act-a-like. Its not my best work, for sure, but it works. It burps out a X11 geometry string relative to the size of the original image, e.g. "1024x768+256+128"

Re: Getting a HBITMAP for use in SetBitmap()

Posted: 2008-02-07T23:13:12-07:00
by Bob-O-Rama
I'll give it a try! That will certainly cut out a bunch of steps. Now that I see how simple it is. I'm sort of kicking myself for not attempting to do the same. :-)

-- Bob