The RectVisible function determines whether any part of the specified rectangle lies within the clipping region of a device context.
- Code: Select all
function RectVisible(DC: HDC; const Rect: TRect): BOOL; stdcall;
The PtVisible function determines whether the specified point is within the clipping region of a device context.
- Code: Select all
function PtVisible(DC: HDC; X, Y: Integer): BOOL; stdcall;
Drawing on a canvas is very time-consuming, especially when there are many things to draw. Using two mentioned APIs, we can determine which parts of a canvas is updated, and redraw only those parts to save lot of cpu time. Sounds great! Yeah?
However, there is a fact that says: "There's always something to suck". Let I tell you when these two APIs suck. To have a wrong return value, the following conditions should be satisfied:
- The DC parameter shoud be a metafile device context (e.g. TMetafileCanvas.Handle).
- The dimension of metafile device context (DC) should be bigger than dimension of its referenced device context (RefDC parameter of TMetafileCanvas constructor).
- The Rect parameter should be outside of the referenced device context's bounding rectangle (RefDC). Obviously, it should be inside bounding rectangle of the metafile device context (DC).
- GREEN RECTANGLE
The RectVisible API tells the rectangle is visible, which is true. - RED RECTANGLE
The RectVisible API tells the rectangle is not visible, which is wrong because you are seeing it with your own eyes.
Maybe there's no bug in these APIs, and I just did something wrong.