同事演示了一个.NET的的PNG异形窗口.挺漂亮.于是也想用Delphi显摆一个.
关于Delphi用PNG做异形窗口的资料有不少.都是用GDIPlus或者TPNGImage组件加载PNG图像做的.但是我很懒,不想引用的GDIPlus,也不想去找PNGImage下载.
好在从Delphi2009开始Delphi中就收购了PNGImage,并集成到后继的版本中.Delphi2010又包装了微软的IWICImagingFactory接口,这样处理PNG的工作就交给操作系统去做了.
函数很简单一共就几行,关键就是UpdateLayeredWindow.
发现CodeGear真让我上火.他们收工了PNGImage以后搞的东西居然改出了问题.透明盒渐变都有问题.做异形窗口该渐变部分居然是透明的.该透明的部分居然是不透明的.看了一下被收购前的PNGImage一点问题都没有.CodeGear真实的.
只好用Delphi2010提供的IWICImagingFactory接口的包装了,这次PNG的处理交给微软的操作系统了,一点问题也没有.其 他版本的Delphi只要能对IWICImagingFactory进行包装,也一样能处理.但还是Delphi2010最方便.什么控件也不用,多余的 东西都不要.
代码如下,很简单吧:)
{*******************************************************}
{?????????????????????????????????????????????????????? }
{?????? 异形窗口??????????????????????????????????????? }
{?????????????????????????????????????????????????????? }
{?????? 2009.12.4 王? 锐??????????????????????????????? }
{?????????????????????????????????????????????????????? }
{*******************************************************}
unit UnitYXForm;
interface
uses
Windows, Forms, Classes, Graphics;
//从文件加载PNG
procedure YXForm_FromFile(AForm : TForm; AFileName : String);
//从资源加载PNG
procedure YXForm_FromResource(AForm : TForm; ResName : String; ResType : PWideChar; Instance : HINST = 0);
//从图像对象加载
procedure YXForm_FromGraphic(AForm : TForm; AGraphic : TGraphic);
implementation
procedure YXForm_FromFile(AForm : TForm; AFileName : String);
var
wic : TWICImage;
begin
wic := TWICImage.Create;
wic.LoadFromFile(AFileName);
YXForm_FromGraphic(AForm, wic);
wic.Free;
end;
procedure YXForm_FromResource(AForm : TForm; ResName : String;ResType : PWideChar; Instance : HINST);
var
wic : TWICImage;
r : TResourceStream;
begin
if Instance = 0 then
Instance := HInstance;
r := TResourceStream.Create(Instance, ResName, ResType);
wic := TWICImage.Create;
wic.LoadFromStream(r);
YXForm_FromGraphic(AForm, wic);
wic.Free;
r.Free;
end;
procedure YXForm_FromGraphic(AForm : TForm; AGraphic : TGraphic);
var
ptDst, ptSrc: TPoint;
Size: TSize;
BlendFunction: TBlendFunction;
bmp : TBitmap;
begin
bmp := TBitmap.Create;
bmp.Assign(AGraphic);
ptDst := Point(AForm.Left, AForm.Top);
ptSrc := Point(0, 0);
Size.cx := AGraphic.Width;
Size.cy := AGraphic.Height;
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := $FF; // 透明度
BlendFunction.AlphaFormat := AC_SRC_ALPHA;
SetWindowLong(AForm.Handle, GWL_EXSTYLE, GetWindowLong(AForm.Handle,
GWL_EXSTYLE) or WS_EX_LAYERED);
UpdateLayeredWindow(AForm.Handle,
AForm.Canvas.Handle,
@ptDst,
@Size,
bmp.Canvas.Handle,
@ptSrc,
0,
@BlendFunction,
ULW_ALPHA);
bmp.Free();
end;
end.
想要用的时候很简单,举个例子:
ff := TForm2.Create(Self);
YXForm_FromFile(ff, ‘c:/a.png’);
ff.Show;
实现动画也很容易.只要不停地YXForm_FromFile(ff, ‘c:/a.png’);调用一套动作PNG就可以了.
效果如下:
Pingback引用通告: psixolog
Pingback引用通告: psyhelp_on_line
Pingback引用通告: coronavirus
Pingback引用通告: PSYCHOSOCIAL
Pingback引用通告: rasstanovka hellinger
Pingback引用通告: Cherekasi film 2020
Pingback引用通告: film doktor_liza
Pingback引用通告: djoker film
Pingback引用通告: viagra
Pingback引用通告: t.me/psyhell
Pingback引用通告: Ïñèõîëîã îíëàéí
Pingback引用通告: bitly.com
Pingback引用通告: viagra 100mg
Pingback引用通告: viagra price
Pingback引用通告: viagra online
Pingback引用通告: buy viagra online
Pingback引用通告: viagra coupon
Pingback引用通告: cheap viagra
Pingback引用通告: cialis
Pingback引用通告: cialis coupon
Pingback引用通告: canadian pharmacy cialis
Pingback引用通告: cialis 5mg
Pingback引用通告: bitly
Pingback引用通告: movies-tekstmovies-tekst
Pingback引用通告: Zemlyane 2005 smotret onlajn
Pingback引用通告: smotret onlajn besplatno v kachestve hd 1080
Pingback引用通告: gusmeasu.com
Pingback引用通告: movies-unhinged-film
Pingback引用通告: malenkie-zhenshhiny-2020
Pingback引用通告: dom 2
Pingback引用通告: zoom-psykholog
Pingback引用通告: zoom-viber-skype
Pingback引用通告: Vratar Galaktiki Film, 2020
Pingback引用通告: Vratar
Pingback引用通告: Cherkassy 2020
Pingback引用通告: chernobyl-hbo-2019-1-sezon
Pingback引用通告: moskva-psiholog
Pingback引用通告: batmanapollo.ru
Pingback引用通告: 323
Pingback引用通告: 525
Pingback引用通告: dom2-ru
Pingback引用通告: psy psy psy psy
Pingback引用通告: krsmi.ru
Pingback引用通告: like-v.ru
Pingback引用通告: CFOSPUK
Pingback引用通告: MAMprEj
Pingback引用通告: fgu0ygW
Pingback引用通告: batmanapollo
Pingback引用通告: tsoy
Pingback引用通告: 44548
Pingback引用通告: 44549
Pingback引用通告: hod-korolevy-2020
Pingback引用通告: HD
Pingback引用通告: 158444
Pingback引用通告: groznyy-serial-2020
Pingback引用通告: 38QvPmk
Pingback引用通告: bitly.com/doctor-strange-hd
Pingback引用通告: bitly.com/eternals-online
Pingback引用通告: bitly.com/maior-grom
Pingback引用通告: matrica-film
Pingback引用通告: dzhonuikfilm4
Pingback引用通告: bitly.com/batman20212022
Pingback引用通告: bitly.com/venom-2-smotret-onlajn
Pingback引用通告: bitly.com/nevremyaumirat
Pingback引用通告: bitly.com/kingsmankingsman
Pingback引用通告: bitly.com/3zaklyatie3
Pingback引用通告: bitly.com/1dreykfilm
Pingback引用通告: bitly.com/topgunmavericktopgun
Pingback引用通告: bitly.com/flash2022
Pingback引用通告: bitly.com/fantasticheskietvari3
Pingback引用通告: bitly.com/wonderwoman1984hd
Pingback引用通告: Human design
Pingback引用通告: 1444
Pingback引用通告: cleantalkorg2.ru
Pingback引用通告: 232dfsad
Pingback引用通告: cleantalkorg2.ru/sitemap.xml
Pingback引用通告: join vk
Pingback引用通告: vk login
Pingback引用通告: svaty7sezon
Pingback引用通告: svaty 7 sezon
Pingback引用通告: svaty 7
Pingback引用通告: tik tok
Pingback引用通告: 666
Pingback引用通告: The Revenant
Pingback引用通告: 00-tv.com
Pingback引用通告: 2021
Pingback引用通告: D4
Pingback引用通告: 777
Pingback引用通告: link
Pingback引用通告: 4569987
Pingback引用通告: news news news
Pingback引用通告: psy
Pingback引用通告: psy2022
Pingback引用通告: projectio-freid
Pingback引用通告: kinoteatrzarya.ru
Pingback引用通告: topvideos
Pingback引用通告: video
Pingback引用通告: afisha-kinoteatrov.ru
Pingback引用通告: Ukrainskie-serialy
Pingback引用通告: site
Pingback引用通告: top
Pingback引用通告: soderzhanki-3-sezon-2021.online