Hey there,
I know this is a very fundamental thing (that I should already know).
I've forgotten the process to copy a BITMAP to another BITMAP.
I understand that you use BitBlt() via device contexts but, I can't remember the exact process.
I've only ever drawn a bitmap to a Window DC.
I have the HDC to the destination Bitmap.
Where do I go from there?
I think it goes something like this..
1 2 3 4 5 6 7 8 9 10
HBITMAP bhSrc(NULL);
HBITMAP bhDest(NULL);
// Create the bitmaps etc..
/* The part where I get mixed up, is how I make the corresponding Bitmaps
and DCs compatible with each other. */
BitBlt(hdcDest, destLeft, destTop, destWid, destHigh,
hdcSrc, srcLeft, srcTop, SRCCOPY);
HBITMAP bhsrc = /*whatever*/;
HBITMAP bhdst = /*whatever*/;
// Create DCs. Making them compatible with 'NULL' means they are compatible with the
// display (which is typically good enough unless your display is running less than 32-bit
// color)
HDC srcdc = CreateCompatibleDC(NULL);
HDC dstdc = CreateCompatibleDC(NULL);
// Put the bitmaps into the DCs. Be sure to record the original HBITMAP for cleanup
HBITMAP srcorig = (HBITMAP)SelectObject(srcdc,bhsrc);
HBITMAP dstorig = (HBITMAP)SelectObject(dstdc,bhdst);
// Blit
BitBlt( ... );
// cleanup - put the original bitmaps back in the DC
SelectObject(srcdc,srcorig);
SelectObject(dstdc,dstorig);
// delete the DCs we created
DeleteDC(srcdc);
DeleteDC(dstdc);
It's worth noting that if you are doing several operations with these bitmaps, it's best to create a DC once along with the bitmap... and keep the DC/bmp/oldbmp together throughout the lifetime of the image.