Microsoft Docs

BitBlt function

The BitBlt function performs a bit‑block transfer of the color data corresponding to a rectangle of pixels from one device context to another.

Syntax

BOOL BitBlt(
    HDC   hdcDest,
    int   nXDest,
    int   nYDest,
    int   nWidth,
    int   nHeight,
    HDC   hdcSrc,
    int   nXSrc,
    int   nYSrc,
    DWORD dwRop
);

Parameters

ParameterDescription
hdcDestHandle to the destination device context.
nXDestX‑coordinate of the upper‑left corner of the destination rectangle.
nYDestY‑coordinate of the upper‑left corner of the destination rectangle.
nWidthWidth of the source and destination rectangles, in logical units.
nHeightHeight of the source and destination rectangles, in logical units.
hdcSrcHandle to the source device context.
nXSrcX‑coordinate of the upper‑left corner of the source rectangle.
nYSrcY‑coordinate of the upper‑left corner of the source rectangle.
dwRopRaster‑operation code. See Raster‑Operation Codes.

Return value

If the function succeeds, the return value is non‑zero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Raster‑Operation Codes

Commonly used dwRop values include:

CodeDefinition
SRCCOPY (0x00CC0020)Copies the source rectangle directly to the destination rectangle.
SRCAND (0x008800C6)Combines the source and destination rectangles using the Boolean AND operator.
SRCINVERT (0x00660046)Combines the source and destination rectangles using the Boolean XOR operator.
SRCPAINT (0x00EE0086)Combines the source and destination rectangles using the Boolean OR operator.

Example

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
    HWND      hWnd = GetDesktopWindow();
    HDC       hDC  = GetDC(hWnd);
    HDC       memDC;
    HBITMAP   hBmp;
    RECT      rc;

    GetClientRect(hWnd, &rc);
    memDC = CreateCompatibleDC(hDC);
    hBmp  = CreateCompatibleBitmap(hDC, rc.right, rc.bottom);
    SelectObject(memDC, hBmp);

    // Fill the memory DC with a solid color.
    FillRect(memDC, &rc, (HBRUSH)(COLOR_WINDOW+1));

    // Copy the memory DC to the screen.
    BitBlt(hDC, 0, 0, rc.right, rc.bottom, memDC, 0, 0, SRCCOPY);

    // Cleanup.
    DeleteObject(hBmp);
    DeleteDC(memDC);
    ReleaseDC(hWnd, hDC);
    return 0;
}

Requirements

See also