OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Constructing and Destroying TRegion

Regions come in many shapes and sizes, from simple rectangles and rectangles with rounded corners to elaborate polygonal shapes.

You can determine the shape of your region by using a particular constructor. You can also indirectly construct a region from a handle to a region or from an existing TRegion object.

TRegion provides a default constructor that produces an empty rectangular region. You can use the function TRegion::SetRectRgn to initialize an empty TRegion object. For example, suppose you derive a class from TRegion. In the constructor for your derived class, call SetRectRgn to initialize the region. This prevents you from having to call TRegion's constructor explicitly:

class TMyRegion : public TRegion
{
public:
TMyRegion(TRect& rect);
.
.
.
};
TMyRegion::TMyRegion(TRect& rect)
{
// Initialize the TRegion base with rect.
SetRectRgn(rect);
}

You can directly create a TRegion from a number of different sources. To create a simple rectangular region, use the following constructor:

TRegion(const TRect& rect);

This constructor creates a rectangular region from the logical coordinates in the TRect object. To create a rectangular region with rounded corners, use the following constructor:

TRegion(const TRect& rect, const TSize& corner);

This constructor creates a rectangular region from the logical coordinates in the TRect object, then rounds the corners into an ellipse. The height and width of the ellipse used is defined by the values in the TSize object.

To create an elliptical region, use the following constructor:

TRegion(const TRect& e, TEllipse);

This constructor creates an elliptical region bounded by the logical coordinates contained in the TRect structure. TEllipse is an enumerated value with only one possible value, Ellipse. A call to this constructor looks something like this:

TRect rect(20, 20, 80, 60);
TRegion rgn(rect, TRegion::Ellipse);

To create regions with an irregular polygonal shape, use the following constructor:

TRegion(const TPoint* points, int count, int fillMode);

points is an array of TPoint objects. Each TPoint contains the logical coordinates of a vertex of the polygon. count indicates the number of points in the points array. fillMode indicates how the region should be filled, either ALTERNATE or WINDING.

There is another constructor that you can use to create regions consisting of multiple irregular polygonal shapes:

TRegion(const TPoint* points, const int* polyCounts,
int count, int fillMode);

As in the other polygonal region constructor, points is an array of TPoint objects. But for this constructor, points contains the vertex points of a number of polygons. polyCounts indicates the number of points in the points array for each polygon. count indicates the total number of polygons in the region and the number of members in the polyCount array. fillMode indicates how the region should be filled, either ALTERNATE or WINDING.

For example, suppose you are constructing a region that encompasses two triangular areas. Each triangle would consist of three points. Therefore points would have six members, three for each triangle. polyPoints would have two members, one for each triangle. Each member of polyPoints would have the value 3, indicating the number of points in the points array that belongs to each polygon. count would have the value 2, indicating that the region consists of two polygons.

You can create a TRegion from an existing HRGN, as follows:

TRegion(HRGN handle, TAutoDelete autoDelete = NoAutoDelete);

This constructor is used to obtain an ObjectWindows object as an alias to a regular Windows handle received in a message.

You can also create a new TRegion object from an existing TRegion object:

TRegion(const TRegion& region);

The destructor ~TRegion deletes the region and its storage space.

See Also