BitBlt

Syntax

BOOL BitBlt(hDestDC,X,Y,nWidth,nHeight,hSrcDC,XSrc,YSrc,dwRop)

This function moves a bitmap from the source device given by the hSrcDC parameter to the destination device given by the hDestDC parameter. The XSrc and YSrc parameters specify the origin on the source device of the bitmap that is to be moved. The X, Y, nWidth, and nHeight parameters specify the origin, width, and height of the rectangle on the destination device that is to be filled by the bitmap. The dwRop parameter (raster operation) defines how the bits of the source and destination are combined.

Parameter Type/Description  

hDestDC HDC Identifies the device context that is to receive the bitmap.  
X int Specifies the logical x-coordinate of the upper-left corner of the destination rectangle.  
Y int Specifies the logical y-coordinate of the upper-left corner of the destination rectangle.  
nWidth int Specifies the width (in logical units) of the destination rectangle and source bitmap.  
nHeight int Specifies the height (in logical units) of the destination rectangle and source bitmap.  
hSrcDC HDC Identifies the device context from which the bitmap will be copied. It must be NULL if the dwRop parameter specifies a raster operation that does not include a source.  
XSrc int Specifies the logical x-coordinate of the upper-left corner of the source bitmap.  
YSrc int Specifies the logical y-coordinate of the upper-left corner of the source bitmap.  
dwRop DWORD Specifies the raster operation to be performed. Raster-operation codes define how the graphics device interface (GDI) combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. For a list of raster-operation codes, see Table R.1, “Raster Operations.”  

Return Value

The return value specifies whether the bitmap is drawn. It is nonzero if the bitmap is drawn. Otherwise, it is zero.

Comments

GDI transforms the nWidth and nHeight parameters, once by using the destination display context, and once by using the source display context. If the resulting extents do not match, GDI uses the StretchBlt function to compress or stretch the source bitmap as necessary. If destination, source, and pattern bitmaps do not have the same color format, the BitBlt function converts the source and pattern bitmaps to match the destination. The foreground and background colors of the destination are used in the conversion.

If BitBlt converts monochrome bitmaps to color, it sets white bits (1) to the background color and black bits (0) to the foreground color. The foreground and background colors of the destination device context are used. To convert color to monochrome, BitBlt sets pixels that match the background color to white (1), and sets all other pixels to black (0). The foreground and background colors of the color-source device context are used.

The foreground color is the current text color for the specified device context, and the background color is the current background color for the specified device context.

Not all devices support the BitBlt function. For more information, see the RC_BITBLT raster capability in the GetDeviceCaps function, later in this chapter.

Table R.1 lists the various raster-operation codes for the dwRop parameter:

Table R.1 Raster Operations

Code Description

BLACKNESS Turns all output black.
DSTINVERT Inverts the destination bitmap.
MERGECOPY Combines the pattern and the source bitmap using the Boolean AND operator.
MERGEPAINT Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.
NOTSRCCOPY Copies the inverted source bitmap to the destination.
NOTSRCERASE Inverts the result of combining the destination and source bitmaps using the Boolean OR operator.
PATCOPY Copies the pattern to the destination bitmap.
PATINVERT Combines the destination bitmap with the pattern using the Boolean XOR operator.
PATPAINT Combines the inverted source bitmap with the pattern using the Boolean OR operator. Combines the result of this operation with the destination bitmap using the Boolean OR operator.
SRCAND Combines pixels of the destination and source bitmaps using the Boolean AND operator.
SRCCOPY Copies the source bitmap to the destination bitmap.
SRCERASE Inverts the destination bitmap and combines the result with the source bitmap using the Boolean AND operator.
SRCINVERT Combines pixels of the destination and source bitmaps using the Boolean XOR operator.
SRCPAINT Combines pixels of the destination and source bitmaps using the Boolean OR operator.
WHITENESS Turns all output white.