Creating an elliptical Form

Here's an example of how to create an elliptical Form using Windows Regions.  Other shapes are possible, in fact almost any shape is possible if you have the time to calculate all the points (note: an alternative to calculating individual points of a shape is to use the CombineRgn API function).  The best aspect of Regions lies in the fact that mouse capture is limited to the displayed region.  Look in the Win API help file for "Regions" for more information. 

KEYWORDS:  SetWindowRgn, CreateEllipticRgn, CombineRgn, GetClientRect 



 

//---------------------------------------------------------------------------

__fastcall TRegionForm::TRegionForm(TComponent* Owner) 
    : TForm(Owner) 

    RECT R = GetClientRect(); 
    HRGN MyRgn = CreateEllipticRgn(0, 0, R.right, R.bottom); 
    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.