- // handle to bitmap
- HBITMAP hwndToHbitmap(HWND hwnd)
- {
- // get the DC of the handle
- HDC hDC = GetDC(hwnd);
- // the rect struct
- RECT rect;
- // get the rect of the handle
- GetClientRect(hwnd, &rect);
- // create a compatible dc for the hDC
- HDC hDCMem = CreateCompatibleDC(hDC);
- // create a compatible bitmap for the hDC
- HBITMAP hBitMap = CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
- // selects an object into a specified device context
- // the second parameter is als brush font pen and region
- // the first parameter is a handle point to the device context
- HBITMAP hOldMap = (HBITMAP)SelectObject(hDCMem, hBitMap);
- //
- BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);
- hBitMap = (HBITMAP)SelectObject(hDCMem, hOldMap);
- return hBitMap;
- }