This is what i used with Delphi sometime. It is my own experiment with polygons but it worked back then... It's basically making a region from horizontal line segments. (you may need Windows in uses clause, as this is not cross platform):
// Use this with SetWindowRgn to reshape your components and forms!
function CreateBitmapRgn(c: TCanvas; Width,Height: Word): HRGN;
var p: array[0..30000] of TPoint;
vertex: array[0..10000] of integer;
trc,i,j,pm: integer; drawing: boolean;
begin
pm:=-1; drawing:=false; trc:=c.Pixels[0,0];
for j:=0 to height-1 do
for i:=0 to width-1 do
if (c.Pixels[i,j]=trc) or (i>=width-1) then begin
if drawing then begin
drawing:=false;
p[pm*3+1]:=point(i,j); p[pm*3+2]:=point(i,j+1);
end;
end else if not drawing then begin
drawing:=true;
inc(pm); vertex[pm]:=3; p[pm*3]:=point(i,j);
end;
result:=CreatePolyPolygonRgn(p,vertex,pm+1,WINDING);
end;
You can call with like:
var rgn: HRGN; bmp: TBitmap;
begin
bmp:=TBitmap.Create;
bmp.LoadFromFile('WindowShape.bmp');
CreateBitmapRgn(bmp.canvas, bmp.width, bmp.height);
SetWindowRgn(form1.handle, rgn, true);
bmp.Free;
end;
Beauty of the function is that you can use it to also reshape any other component on form too. A circle panel for instance.