How to convert HDC to CBitmap?
-
Hello guys, I wanted to convert an HDC to a CBitmap object but I don't know how to. How can I possibly manipulate HDC and probably create a CBitmap from it. Hope you can help me with this one. It will be a big help. Thanks.
-
Hello guys, I wanted to convert an HDC to a CBitmap object but I don't know how to. How can I possibly manipulate HDC and probably create a CBitmap from it. Hope you can help me with this one. It will be a big help. Thanks.
Can you more explain HDC is a handle to device context and HBITMPA is a handle to a bitmap,for make a bitmap you can use of CreateCompatibaleBitmap.
-
Hello guys, I wanted to convert an HDC to a CBitmap object but I don't know how to. How can I possibly manipulate HDC and probably create a CBitmap from it. Hope you can help me with this one. It will be a big help. Thanks.
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);