Creating
a triangular Form
Creating a triangular Form can be accomplished
by using Windows Regions. Specifically, the CreatePolygonRgn API
function can be used to create a triangular region which can then be assigned
as the region of a Form via the SetWindowRgn API function.
KEYWORDS: SetWindowRgn, CreatePolygonRgn
|
//---------------------------------------------------------------------------
__fastcall TRegionForm::TRegionForm(TComponent*
Owner)
:
TForm(Owner)
{
//
The parameters to CreatePolygonRgn are the array of
// points (relative to the Control whose Handle is passed
// to the SetWindowRgn function), the total number of points,
// and filling mode (WINDING or ALTERNATE).
TPoint
P[3];
P[0].x
= 0;
P[0].y
= 0;
P[1].x
= Width;
P[1].y
= 0;
P[2].x
= static_cast<int>(Width / 2);
P[2].y
= Height;
HRNG
MyRgn = CreatePolygonRgn(P, 3, WINDING);
SetWindowRgn(Handle,
MyRgn, true);
}
|
Usually, you'd need to call DeleteObject() for every region that you
create. However, once you assign a region as the region of a window
via SetWindowRgn, there is no need to destroy it -- Windows will handle
this automatically.
|