设置不规则窗体形状(100分)

  • 主题发起人 主题发起人 happy3001
  • 开始时间 开始时间
H

happy3001

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用指定位图和指定透明色(keyc),设置窗体形状,有一个sample如下,我怎么使用没有效果,
到是什么都看不到了。
帮帮我?
rgn;=CreateRectRgn(0,0,0,0);
对位图上的每一点(x,y)颜色c
if c<>Keyc
then begin
comine into rgn;
end;
setwindowrgn(handle,rgn);
 
直接调用下面的方法就可以了。
//
// -'`"_ -'`" /
// / / / "
// / ///__ / ___ / 西安科技学院143信箱 710054
// | | / -"`.-( / |
// | | | | /" | | 万 重
// | / / "-" / / |
// /___/ / (o o) / (__/ 电邮: mantousoft@sina.com
// __| _ _ |__
// ( ( ) ) 网址: http://mantousoft.51.net
// /_/.-.___.-./_/
// __ | | __ QQ : 6036742
// | /.| |./ |
// | '#. .#' |
// |__/ '"" /__| 2001.3.1
// -/ /-
//

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;
 
我想用图片做背景的,设置为他的形状,在把他画上去
罗云彬的卡通小闹钟 的效果
 
这个就是呀,他把图片Pixels[0,0]的颜色作为透明色。

源程序:
http://www.islet8.com/codes/download/rgnform_sc.rar
 
接受答案了.
 
后退
顶部