[WinAPI] Cum se captureaza ferestre layered?

Folosire Windows API in programe C/C++ (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi

[WinAPI] Cum se captureaza ferestre layered?

Post by Ovidiu Cucu » 19 Jun 2009, 10:55

Problema: Am facut o captura de ecran utilizand un memory DC si functia BitBlt. Functioneaza, insa ferestrele avand stilul WS_EX_LAYERED nu apar in imaginea rezultata. Cum se poate rezolva?

Solutia: Se poate rezolva simplu adaugand flag-ul CAPTUREBLT la apelul functiei BitBlt.

Exemplu:

Code: Select all

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;
}

<< Back to Windows API Index



Post Reply