这是画窗体的代码,从别的窗体创建此窗体,可在生成25个以后,就会报错
procedure TmyForm.FormCreate(Sender: TObject);
var
w1: TBitmap;
w2: TColor;
rgn: HRGN;
begin
isTime := false;
image1.BringToFront;
image1.Left := 273;
image1.Top := 53;
atime := 0;
w1 :=TBitmap.Create;
w1.LoadFromFile('./skin3.bmp');
w2 := image2.Canvas.Pixels[0,0];
rgn := CreateRegion(w1, w2, Handle);
if rgn<>0 then
begin
SetWindowRgn(Handle, rgn, true);
end;
height := w1.Height ;
width := w1.Width ;
w1.Free;
SetWindowPos(self.handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;{myForm.FormCreate}
function TmyForm.CreateRegion(wMask: TBitmap; wColor: TColor; hControl: THandle): HRGN;
var
dc, dc_c: HDC;
Rgn, TempRgn: HRGN;
X, Y, BeginY: Integer;
line: boolean;
color: TColor;
begin
Rgn := CreateRectRgn(0, 0, 0, 0);{先初始化一个空的区域给Rgn。}
for X := 0 to wMask.Width - 1 do
begin
line := False;
for Y := 0 to wMask.Height - 1 do
begin
color := GetPixel(dc_c, X, Y);
if not (color = wColor) then
begin
if not line then
begin
line := True;
BeginY:= Y;
end;
end;
if (color = wColor) or (Y = wMask.Height-1 ) then
begin
if line then
begin
line := False;
TempRgn := CreateRectRgn(X, BeginY, X + 1, Y);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
{把图形以连续得线段为单位生成区域,并且合并到总的区域中}
end;
end;
end;
end;
ReleaseDC(hControl, dc);
DeleteObject(dc);
Result := Rgn;
end;{TmyForm.CreateRegion}