窗口透明问题,有透明底色与图片阴影运算出来不想要的边 ( 积分: 200 )

  • 主题发起人 主题发起人 emitsong
  • 开始时间 开始时间
E

emitsong

Unregistered / Unconfirmed
GUEST, unregistred user!
在Form中设置
TransparentColor:=true;
TransparentColorValue:=clnone;
color:=clnone;

结果发现了阴影变成了黑边,
如果将 form1.Brush.Style:=bsclear;上面的语句屏蔽,发现黑边没了,但窗口不透明了
看了TForm原码,发现用了下面代码
if not (csDesigning in ComponentState) and
(Assigned(SetLayeredWindowAttributes)) and HandleAllocated then
begin
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if FAlphaBlend or FTransparentColor then
begin
if (AStyle and WS_EX_LAYERED) = 0 then
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);
RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
end;
end;
/////////////////////////////////
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
关键这句里FTransparentColor如过为clnone,结果他当成黑的了,有没有空值表示方法,让他达到form1.Brush.Style:=bsclear;的效果,又有透明的功能,这样图片的阴影就完全显示出来了
注:我用了pngimage所以图片都为有阴影的透明图片
 
在Form中设置
TransparentColor:=true;
TransparentColorValue:=clnone;
color:=clnone;

结果发现了阴影变成了黑边,
如果将 form1.Brush.Style:=bsclear;上面的语句屏蔽,发现黑边没了,但窗口不透明了
看了TForm原码,发现用了下面代码
if not (csDesigning in ComponentState) and
(Assigned(SetLayeredWindowAttributes)) and HandleAllocated then
begin
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if FAlphaBlend or FTransparentColor then
begin
if (AStyle and WS_EX_LAYERED) = 0 then
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);
RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
end;
end;
/////////////////////////////////
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
关键这句里FTransparentColor如过为clnone,结果他当成黑的了,有没有空值表示方法,让他达到form1.Brush.Style:=bsclear;的效果,又有透明的功能,这样图片的阴影就完全显示出来了
注:我用了pngimage所以图片都为有阴影的透明图片
 
你可以直接采用 gdiPlus.dll 进行 paint,参考
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3292675
 
gdiPlus.dll 好像慢些
 
能有详细的代码吗,gdiplus.dll
 
到http://www.01cn.net/中,小雨哥 有一篇专门讨论这个的心得贴子,你可去看看的
使用 2000 特有的 LayeredWindow 做异形窗口

小雨哥
Windows 2000 以后,为适应界面的华丽化倾向,系统中增加了 LayeredWindow
窗口的支持。一旦 Form 被定义为利用 LayeredWindow ,窗口的绘图不再响应延
用多年的 WM_Paint 消息,下面的例子展示了 LayeredWindow 的使用。
http://www.01cn.net/noncgi/attach/2004/10/31/7419-LayeredWindow.rar
(注:图片存在于 Bmp.res 资源文件中了,不要删除这个资源文件)
我们已经很熟悉 SetLayeredWindowAttributes 这个函数。
 
你有那个有阴影的球的代码吗
 
這個簡單。方法:
1、建立兩個FORM窗體。
2、設置第二個FORM透明50%,同時兩個窗體要調整它們的位置。
3、先打開第二個再接著打開第一個。

這樣就行了。
 
bbscom 方法是简单的加阴影,如果碰到不规则图形就完了
 
后退
顶部