Is there a way to clone a HBITMAP?

This could be exceedingly simple, I'm lost though.

At one point in my app I do this:

HBITMAP hbmSurface;
void* buffer = NULL;
hbmSurface = ::CreateDIBSection(0, pPacket->BitmapInfo(), DIB_RGB_COLORS, &buffer, NULL, 0);

At a later point in execution, I no longer have access to pPacket->BitmapInfo()  in order to create a new DIBSection. But I do have access to hbmSurface.


is there a "clone" or a way for me to get the BITMAPINFO from the hbmSurface, so that I can create a new DIBSection?

EDIT:   - OR -
I also have this following the creation of the DIBSection above:

      memDC.CreateCompatibleDC(NULL);

      // select bitmap into memory device context (memDC) so we can draw to it.
      if (hbmSurface)
            hbmOldSurface = (HBITMAP)memDC.SelectObject(hbmSurface);


My "goal" is to be able to create a new memory surface that matches memDC in dimension and bitmap info paramaters.   At the point in execution that I need to do this, I have access to both the memDC and the hbmSurface, so an approach to create a duplicate is what I'm after, either way.

thanks!
-Paul
PMH4514Asked:
Who is Participating?
 
PMH4514Author Commented:
oh look at that, I guess I didn't realize GetDIBits retrieved more than just the bits.. I think this will work!
0
 
PMH4514Author Commented:
jamie -

that msdn link states:
"The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function."

this could be a problem.  The bitmap I'm trying to refrence to create a new similar memory surface, is already selected into it's own memory surface.

Thoughts?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Jaime OlivaresSoftware ArchitectCommented:
Exactly what info on bitmap are you interested in?
0
 
PMH4514Author Commented:
just the dimensions..

my understanding is that to create an offscreen surface you need to first CreateCompatibleDC   - that leaves you with a DC with a 1x1 monochrome bitmap selected into it..  So I then need to select a bitmap into the DC in order to "give my DC the drawing dimensions I want" - in my case, hbmSurface is the bitmap that was selected into a memory DC earlier. I now need to create a new memory DC, for yet another "overlay".  So I do CreateCompatibleDC  and then I need to select into it a bitmap.   I can't just select hbmSurface into that new DC, as that bitmap is already selected into another DC.. So I need to "create a new bitmap" that has the same "info" as the other one.

does that make sense? :)
0
 
Jaime OlivaresSoftware ArchitectCommented:
Have you tried GetBitmapDimensionEx ?
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1l4o.asp
0
 
PMH4514Author Commented:
I had actually. but this:

"The retrieved dimensions must have been set by the SetBitmapDimensionEx function."

was not the case.  
0
 
PMH4514Author Commented:
I prefer to get the BITMAPINFO anyway
0
 
Jaime OlivaresSoftware ArchitectCommented:
I have faces this problem in the past but I can't remember how I have solved, maybe is just needed to maintain some size information in paralell or even create your own bitmapinfo structure.
0
 
Jaime OlivaresSoftware ArchitectCommented:
Sorry, it is faced not faces
0
 
PMH4514Author Commented:
>>maybe is just needed to maintain some size information in paralell
Turns out that's what I just tried and it worked quite nicely.
0
 
PMH4514Author Commented:
I'm going to accept your GetDIBits answer as but for my odd situation, that would have been perfect.
0
All Courses

From novice to tech pro — start learning today.