I wanted to make a program that creates a region from a template, and then uses it to cut the window. Here is the program code:
unit Back; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) function RegionFromFile(pict: TPicture; backcolor: TColor): HRGN; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function (pict :TPicture; backcolor: TColor): HRGN; var rgn, resRgn: HRGN; x, y, xFirst: Integer; begin resRgn := CreateRectRgn(0, 0, 0, 0); for y := 0 to pict.Height - 1 do begin x := 0; while x < pict.Width do begin if (pict.Bitmap.Canvas.Pixels[x, y] <> backcolor) then begin xFirst := x; Inc(x); while (x < pict.Width) and (pict.Bitmap.Canvas.Pixels[x, y] <> backcolor) do Inc(x); rgn := CreateRectRgn(xFirst, y, x-1, y+1); CombineRgn(resRgn, resRgn, rgn, RGN_OR); DeleteObject(rgn); end; Inc(x); end; end; RegionFromPicture := resRgn; end; procedure TForm1.FormCreate(Sender: TObject); var pict: TPicture; begin pict := TPicture.Create; pict.LoadFromFile('back.png'); SetWindowRgn(Handle, RegionFromRicture(pict, RGB(255,255,255)), True); end; end.
PS Template file is stored in back.png.