procedure TForm2.Button1Click(Sender: TObject);
Var
frmRegion, tempRegion: HRGN;
i: Integer;
Arect: TRect;
Begin
frmRegion := 0;
For I:= 0
To ControlCount - 1
Do Begin
// create a region for the control
aRect := Controls[i].BoundsRect;
// coordinates have to be window-relative, not client area relative
OffsetRect( aRect, clientorigin.x - left, clientorigin.y - top );
tempRegion := CreateRectRgnIndirect( aRect );
// merge the region with the "summary" region we are building
If frmRegion = 0
Then
frmRegion := tempRegion
Else Begin
CombineRgn( frmRegion, frmRegion, tempRegion, RGN_OR );
DeleteObject( tempRegion );
End;
End;
// create a region for the caption and menu bar and add it to the
// summary
tempregion :=
CreateRectRgn( 0, 0, Width,
GetSystemMetrics( SM_CYCAPTION )+
GetSystemMetrics( SM_CYSIZEFRAME )+
GetSystemMetrics( SM_CYMENU ));
CombineRgn( frmRegion, frmRegion, tempRegion, RGN_OR );
DeleteObject( tempRegion );
SetWindowRgn(
handle, frmRegion, true );
end;