Blt Coordinates

When I introduced the syntax of the PatBlt function, I said that the point (xDest, yDest) specifies the upper left corner of a rectangle and that this rectangle is xWidth units wide and yHeight units high. Actually, although that's also what the Windows documentation says, the statement is not entirely accurate. Before we proceed any further, I need to clear up some confusion concerning the blt functions and coordinates.

BitBlt, PatBlt, and StretchBlt are the only GDI drawing functions that specify logical rectangular coordinates in terms of a logical width and height measured from a single corner. All the other GDI drawing functions that use rectangular bounding boxes require that coordinates be specified in terms of an upper left corner and a lower right corner. For the MM_TEXT mapping mode, the above description of the PatBlt parameters is accurate. For the metric mapping modes, however, it's not. If you use positive values of xWidth and yHeight, then the point (xDest, yDest) will be the lower left corner of the rectangle. If you want (xDest, yDest) to be the upper left corner of the rectangle, the yHeight parameter must be set to the negative height of the rectangle.

To be more precise, the rectangle that PatBlt colors has a logical width given by the absolute value of xWidth and a logical height given by the absolute value of yHeight. These two parameters can be negative. The rectangle is defined by two corners given by the logical points (xDest, yDest) and (xDest + xWidth, yDest + yHeight). The upper left corner of the rectangle is always included in the area that PatBlt modifies. The lower right corner is outside the rectangle. Depending on the mapping mode and the signs of the xWidth and yHeight parameters, the upper left corner of this rectangle could be the point:

(xDest, yDest)

or:

(xDest, yDest + yHeight)

or:

(xDest + xWidth, yDest)

or:

(xDest + xWidth, yDest + yHeight)

If you've set the mapping mode to MM_LOENGLISH and you want to use PatBlt on the square inch at the upper left corner of the client area, you can use:

PatBlt (hdc, 0, 0, 100, -100, dwROP) ;

or:

PatBlt (hdc, 0, -100, 100, 100, dwROP) ;

or:

PatBlt (hdc, 100, 0, -100, -100, dwROP) ;

or:

PatBlt (hdc, 100, -100, -100, 100, dwROP) ;

The easiest way to set the correct parameters to PatBlt is to set xDest and yDest to the upper left corner of the rectangle. If your mapping mode defines y-coordinates as increasing as you move up the display, use a negative value for the yHeight parameter. If your mapping mode defines x-coordinates as increasing to the left (which is almost unheard of), use a negative value for the xWidth parameter.