根据位图做出漂亮的不规则FORM
点击次数:68 次 发布日期:2008-11-09 08:41:06 作者:源代码网
|
源代码网推荐 源代码网推荐 interface 源代码网推荐 源代码网推荐 uses 源代码网推荐 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 源代码网推荐 ExtCtrls, StdCtrls, Buttons; 源代码网推荐 源代码网推荐 type 源代码网推荐 TForm1 = class(TForm) 源代码网推荐 Image1: TImage; 源代码网推荐 Button1: TButton; 源代码网推荐 procedure FormCreate(Sender: TObject); 源代码网推荐 procedure Button1Click(Sender: TObject); 源代码网推荐 procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; 源代码网推荐 Shift: TShiftState; X, Y: Integer); 源代码网推荐 private 源代码网推荐 function CreateRegion(wMask: TBitmap; wColor: TColor; 源代码网推荐 hControl: THandle): HRGN; 源代码网推荐 { Private declarations } 源代码网推荐 public 源代码网推荐 { Public declarations } 源代码网推荐 end; 源代码网推荐 源代码网推荐 var 源代码网推荐 Form1: TForm1; 源代码网推荐 源代码网推荐 implementation 源代码网推荐 源代码网推荐 {$R *.DFM} 源代码网推荐 源代码网推荐 function Tform1.CreateRegion(wMask:TBitmap;wColor:TColor;hControl:THandle): HRGN; 源代码网推荐 var 源代码网推荐 dc, dc_c: HDC; 源代码网推荐 rgn: HRGN; 源代码网推荐 x, y: integer; 源代码网推荐 coord: TPoint; 源代码网推荐 line: boolean; 源代码网推荐 color: TColor; 源代码网推荐 begin 源代码网推荐 dc := GetWindowDC(hControl); 源代码网推荐 dc_c := CreateCompatibleDC(dc); 源代码网推荐 SelectObject(dc_c, wMask.Handle); 源代码网推荐 BeginPath(dc); 源代码网推荐 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; 源代码网推荐 coord.x := x; 源代码网推荐 coord.y := y; 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 if (color = wColor) or (y=wMask.Height-1) then 源代码网推荐 begin 源代码网推荐 if line then 源代码网推荐 begin 源代码网推荐 line := false; 源代码网推荐 MoveToEx(dc, coord.x, coord.y, nil); 源代码网推荐 LineTo(dc, coord.x, y); 源代码网推荐 LineTo(dc, coord.x 1, y); 源代码网推荐 LineTo(dc, coord.x 1, coord.y); 源代码网推荐 CloseFigure(dc); 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 EndPath(dc); 源代码网推荐 rgn := PathToRegion(dc); 源代码网推荐 ReleaseDC(hControl, dc); 源代码网推荐 Result := rgn; 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure TForm1.FormCreate(Sender: TObject); 源代码网推荐 var 源代码网推荐 w1:TBitmap; 源代码网推荐 w2:TColor; 源代码网推荐 rgn: HRGN; 源代码网推荐 begin 源代码网推荐 w1:=TBitmap.Create; 源代码网推荐 w1.Assign(image1.Picture.Bitmap); 源代码网推荐 w2:=w1.Canvas.Pixels[0,0]; 源代码网推荐 rgn := CreateRegion(w1,w2,Handle); 源代码网推荐 if rgn<>0 then 源代码网推荐 begin 源代码网推荐 SetWindowRgn(Handle, rgn, true); 源代码网推荐 end; 源代码网推荐 w1.Free; 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure TForm1.Button1Click(Sender: TObject); 源代码网推荐 begin 源代码网推荐 Close; 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; 源代码网推荐 Shift: TShiftState; X, Y: Integer); 源代码网推荐 begin 源代码网推荐 ReleaseCapture; 源代码网推荐 SendMessage(Handle, WM_SYSCOMMAND, $F012, 0); 源代码网推荐 end; 源代码网推荐 源代码网推荐 end. 源代码网推荐 源代码网供稿. |
