BOOL PtVisible(hdc, nXPos, nYPos) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nXPos; | /* x-coordinate of point to query | */ | |||
int nYPos; | /* y-coordinate of point to query | */ |
The PtVisible function determines whether the specified point is within the clipping region of the given device context.
hdc
Identifies the device context.
nXPos
Specifies the logical x-coordinate of the point.
nYPos
Specifies the logical y-coordinate of the point.
The return is nonzero if the point is within the clipping region. Otherwise, it is zero.
The following example creates a rectangular region, displays a message inside it, and selects the region as the clipping region. The PtVisible function is used to determine whether coordinates generated by a double-click are inside the region. If so, the message changes to “Thank you.” If not, the CombineRgn function is used to create a clipping region that combines the first region with a new region that surrounds the specified coordinates, and the word “Missed!” is displayed at the coordinates.
HDC hdcLocal;
HRGN hrgnClick, hrgnMiss, hrgnCombine;
HBRUSH hbr;
hdcLocal = GetDC(hwnd);
hbr = GetStockObject(BLACK_BRUSH);
hrgnClick = CreateRectRgn(90, 95, 225, 120);
FrameRgn(hdcLocal, hrgnClick, hbr, 1, 1);
TextOut(hdcLocal, 100, 100, "Double-click here.", 18);
SelectClipRgn(hdcLocal, hrgnClick);
if (PtVisible(hdcLocal, XClick, YClick)) {
PaintRgn(hdcLocal, hrgnClick);
FrameRgn(hdcLocal, hrgnClick, hbr, 1, 1);
TextOut(hdcLocal, 100, 100, "Thank you.", 10);
}
else if (XClick > 0) {
hrgnMiss = CreateRectRgn(XClick - 5, YClick - 5, XClick + 60,
YClick + 20);
hrgnCombine = CreateRectRgn(0, 0, 0, 0);
CombineRgn(hrgnCombine, hrgnClick, hrgnMiss, RGN_OR);
SelectClipRgn(hdcLocal, hrgnCombine);
FrameRgn(hdcLocal, hrgnCombine, hbr, 1, 1);
TextOut(hdcLocal, XClick, YClick, "Missed!", 7);
}
InvalidateRect(hwnd, NULL, FALSE);
DeleteObject(hrgnClick);
DeleteObject(hrgnMiss);
DeleteObject(hrgnCombine);
ReleaseDC(hwnd, hdcLocal);