setcliprgn

This function is used to set the clipping region of current drawing device.

void setcliprgn(HRGN hrgn);

Parameters

hrgn

The handle to the region. The coordinates used to create the zone are physical coordinates. If the value is NULL, the clipping region set before the cancellation is canceled.

Return Value

None

Remarks

HEGN is the handle to the representation area defined by windows. When you set the area to a clipping region, the drawing outside any area is invalid (but the outside drawing can still be displayed by overwriting the display buffer).

You can use the windows GDI function to create a region. For example, you can use a function to create a rectangular area:
HRGN CreateRectRgn(int left, int top, int right, int bottom);

In addition, you can use the function CreatellipticRgn to create oval areas, Create Poigon Rgn to create polygon areas, and so on, and also use The CombineRgn to combine areas. For more information on the GDI function of the region, refer to Region Functions in MSDN.

Note: After you create a zone, if you don't use it, perform DeleteObject (HRGN hrgn) to free up system resources for the zone.

Examples

The following code is used to create a rectangular clipping region and draw a circle in that crop area, observe the crop effect.

#include <graphics.h>
#include <conio.h>

int main()
{
	// Initialize the graphics window

	initgraph(640, 480);

	// Create a rectangular area

	HRGN rgn = CreateRectRgn(100, 100, 200, 200);
	// Set the rectangular area to clipping region

	setcliprgn(rgn);
	// Not use rgn anymore, clear the system resource occupied by rgn
	DeleteObject(rgn);

	// Draw a circle, affected by the clipping region, showing only four arcs

	circle(150, 150, 55);

	// Cancel the clipping area that was set before

	setcliprgn(NULL);

	// Draw a circle, no longer affected by the crop area, showing a complete circle

	circle(150, 150, 60);

	// Press any key to exit
	_getch();
	closegraph();
}
(贡献者:Krissi  编辑