BOOL PatBlt(hdc, nLeftRect, nTopRect, nwidth, nheight, fdwRop) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nLeftRect; | /* x-coordinate top-left corner destination rectangle | */ | |||
int nTopRect; | /* y-coordinate top-left corner destination rectangle | */ | |||
int nwidth; | /* width of destination rectangle | */ | |||
int nheight; | /* height of destination rectangle | */ | |||
DWORD fdwRop; | /* raster operation, */ |
The PatBlt function creates a bit pattern on the specified device. The pattern is a combination of the selected brush and the pattern already on the device. The specified raster-operation code defines how the patterns are combined.
hdc
Identifies the device context.
nLeftRect
Specifies the logical x-coordinate of the upper-left corner of the rectangle that receives the pattern.
nTopRect
Specifies the logical y-coordinate of the upper-left corner of the rectangle that receives the pattern.
nwidth
Specifies the width, in logical units, of the rectangle that will receive the pattern.
nheight
Specifies the height, in logical units, of the rectangle that will receive the pattern.
fdwRop
Specifies the raster-operation code that determines how the graphics device interface (GDI) combines the colors in the output operation. This parameter can be one of the following values:
Value | Meaning |
PATCOPY | Copies the pattern to the destination bitmap. |
PATINVERT | Combines the destination bitmap with the pattern by using the Boolean XOR operator. |
PATPAINT | Paints the destination bitmap. |
DSTINVERT | Inverts the destination bitmap. |
BLACKNESS | Turns all output black. |
WHITENESS | Turns all output white. |
The return value is nonzero if the function is successful. Otherwise, it is zero.
The raster operations listed for this function are a limited subset of the full 256 ternary raster-operation codes; in particular, a raster-operation code that refers to a source cannot be used.
Not all devices support the PatBlt function. To determine whether a device supports PatBlt, an application can call the GetDeviceCaps function with the RASTERCAPS index.
The following example uses the CreateBitmap function to create a bitmap with a zig-zag pattern, and then uses the PatBlt function to fill the client area with that pattern:
HDC hdc;
HBITMAP hbmp;
HBRUSH hbr, hbrPrevious;
RECT rc;
int aZigzag[] = { 0xFF, 0xF7, 0xEB, 0xDD, 0xBE, 0x7F, 0xFF, 0xFF };
hbmp = CreateBitmap(8, 8, 1, 1, aZigzag);
hbr = CreatePatternBrush(hbmp);
hdc = GetDC(hwnd);
UnrealizeObject(hbr);
hbrPrevious = SelectObject(hdc, hbr);
GetClientRect(hwnd, &rc);
PatBlt(hdc, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top, PATCOPY);
SelectObject(hdc, hbrPrevious);
ReleaseDC(hwnd, hdc);
DeleteObject(hbr);
DeleteObject(hbmp);