Click to See Complete Forum and Search --> : copying from one DC to another


Mathew Joy
November 26th, 2003, 02:15 AM
BitBlt seems to work only if the destination DC is the client window. I actually want to copy more than one bitmaps to different locations of a dc and then display it on the client window. But I am unable to copy the image from one DC to another. The code is from the WndProc callback function: case WM_PAINT:

hdcClient = BeginPaint (hwnd, &ps) ;

hdcMainMem = CreateCompatibleDC(hdcClient);
hdcMem = CreateCompatibleDC(hdcClient);
SelectObject(hdcMem,hBitmap);
BitBlt(hdcMainMem, 0, 0, 250, 250, hdcMem, 0, 0, SRCCOPY); //just assuming the height and width
BitBlt(hdcClient, 0, 0, 500, 500, hdcMainMem, 0, 0, SRCCOPY);

DeleteDC (hdcMem) ;
DeleteDC (hdcMainMem) ;
ReleaseDC(hwnd,hdcClient);
EndPaint(hwnd, &ps);
break;
Am I doing it correctly?

Marc G
November 26th, 2003, 05:18 AM
You also have to select a hbitmap into hdcMainMem.
Use ::CreateCompatibleBitmap to create this bitmap.

If i understand you correctly, you're also trying to scale your bitmap? If so try to use stretchblt instead ot bitblt.

Mathew Joy
November 26th, 2003, 06:30 AM
Originally posted by Marc G
You also have to select a hbitmap into hdcMainMem.
Use ::CreateCompatibleBitmap to create this bitmap.
Oh! Thanks alot...I was doing trial and error for a couple of days:rolleyes:If i understand you correctly, you're also trying to scale your bitmap? If so try to use stretchblt instead ot bitblt. Yeah...I doing that in my project, but being able to display is the first thing,isn't it?;)