Here's some code that will retrieve the currently selected bitmap from a HDC. It should be noted that GetCurrentObject will only return a valid BITMAP if the supplpied HDC is a memory DC. If I tried to do dcBmp = (HBITMAP)GetCurrentObject(screenDC, OBJ_BITMAP), I'd get garbage results. If the DC you're trying to copy is not a memory DC, the alternative you have is to determine the position on screen of the image, then do a BitBlt from the screenDC to a memoryDC that has already got a HBITMAP selected onto it. Note that having a look into the BitBlt, SelectObject, & CreateCompatibleBitmap may be necessary.
HDC screenDC, memDC;
char buffer\[200\];
BITMAP bmInfo;
HBITMAP dcBmp;
screenDC = GetWindowDC(hwnd);
memDC = CreateCompatibleDC(screenDC);
HBITMAP myBmp = CreateCompatibleBitmap(memDC, 100, 100);
SelectObject(memDC, myBmp);
dcBmp = (HBITMAP)GetCurrentObject(memDC, OBJ\_BITMAP);
if (dcBmp)
{
GetObject(dcBmp, sizeof(bmInfo), &bmInfo);
sprintf(buffer, "Bitmap is: %d x %d pixels.", bmInfo.bmWidth, bmInfo.bmHeight);
MessageBox(hwnd, buffer, "Title", MB\_OK);
}
else
MessageBox(hwnd, "Error", "Title", MB\_ICONEXCLAMATION);