Q: I have made screen capture using a memory DC and BitBlt function. It works OK except that windows having WS_EX_LAYERED style set do not appear in the resulting bitmap. How to resolve this issue?
A: Simple, we have to pass CAPTUREBLT flag to BitBlt function.
Example:
Code:
BOOL CaptureScreen(HBITMAP& hBitmap)
{
HDC hDCScreen = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
const int cx = ::GetDeviceCaps(hDCScreen, HORZRES);
const int cy = ::GetDeviceCaps(hDCScreen, VERTRES);
HDC hDCMem = ::CreateCompatibleDC(hDCScreen);
hBitmap = ::CreateCompatibleBitmap(hDCScreen, cx, cy);
HBITMAP hBmpOld = (HBITMAP)::SelectObject(hDCMem, hBitmap);
// Note: CAPTUREBLT flag is required to capture layered windows
DWORD dwRop = SRCCOPY | CAPTUREBLT;
BOOL bRet = ::BitBlt(hDCMem, 0, 0, cx, cy, hDCScreen, 0, 0, dwRop);
::SelectObject(hDCMem, hBmpOld);
::DeleteDC(hDCMem);
::DeleteDC(hDCScreen);
return bRet;
}