一个最简单的Delphi2010的PNG异形窗口方法

转自我的旧博客

同事演示了一个.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就可以了.

效果如下:

此条目发表在Delphi, 未分类分类目录。将固定链接加入收藏夹。

一个最简单的Delphi2010的PNG异形窗口方法》有102条回应

  1. Pingback引用通告: psixolog

  2. Pingback引用通告: psyhelp_on_line

  3. Pingback引用通告: coronavirus

  4. Pingback引用通告: PSYCHOSOCIAL

  5. Pingback引用通告: rasstanovka hellinger

  6. Pingback引用通告: Cherekasi film 2020

  7. Pingback引用通告: film doktor_liza

  8. Pingback引用通告: djoker film

  9. Pingback引用通告: viagra

  10. Pingback引用通告: t.me/psyhell

  11. Pingback引用通告: Ïñèõîëîã îíëàéí

  12. Pingback引用通告: bitly.com

  13. Pingback引用通告: viagra 100mg

  14. Pingback引用通告: viagra price

  15. Pingback引用通告: viagra online

  16. Pingback引用通告: buy viagra online

  17. Pingback引用通告: viagra coupon

  18. Pingback引用通告: cheap viagra

  19. Pingback引用通告: cialis

  20. Pingback引用通告: cialis coupon

  21. Pingback引用通告: canadian pharmacy cialis

  22. Pingback引用通告: cialis 5mg

  23. Pingback引用通告: bitly

  24. Pingback引用通告: movies-tekstmovies-tekst

  25. Pingback引用通告: Zemlyane 2005 smotret onlajn

  26. Pingback引用通告: smotret onlajn besplatno v kachestve hd 1080

  27. Pingback引用通告: gusmeasu.com

  28. Pingback引用通告: movies-unhinged-film

  29. Pingback引用通告: malenkie-zhenshhiny-2020

  30. Pingback引用通告: dom 2

  31. Pingback引用通告: zoom-psykholog

  32. Pingback引用通告: zoom-viber-skype

  33. Pingback引用通告: Vratar Galaktiki Film, 2020

  34. Pingback引用通告: Vratar

  35. Pingback引用通告: Cherkassy 2020

  36. Pingback引用通告: chernobyl-hbo-2019-1-sezon

  37. Pingback引用通告: moskva-psiholog

  38. Pingback引用通告: batmanapollo.ru

  39. Pingback引用通告: 323

  40. Pingback引用通告: 525

  41. Pingback引用通告: dom2-ru

  42. Pingback引用通告: psy psy psy psy

  43. Pingback引用通告: krsmi.ru

  44. Pingback引用通告: like-v.ru

  45. Pingback引用通告: CFOSPUK

  46. Pingback引用通告: MAMprEj

  47. Pingback引用通告: fgu0ygW

  48. Pingback引用通告: batmanapollo

  49. Pingback引用通告: tsoy

  50. Pingback引用通告: 44548

  51. Pingback引用通告: 44549

  52. Pingback引用通告: hod-korolevy-2020

  53. Pingback引用通告: HD

  54. Pingback引用通告: 158444

  55. Pingback引用通告: groznyy-serial-2020

  56. Pingback引用通告: 38QvPmk

  57. Pingback引用通告: bitly.com/doctor-strange-hd

  58. Pingback引用通告: bitly.com/eternals-online

  59. Pingback引用通告: bitly.com/maior-grom

  60. Pingback引用通告: matrica-film

  61. Pingback引用通告: dzhonuikfilm4

  62. Pingback引用通告: bitly.com/batman20212022

  63. Pingback引用通告: bitly.com/venom-2-smotret-onlajn

  64. Pingback引用通告: bitly.com/nevremyaumirat

  65. Pingback引用通告: bitly.com/kingsmankingsman

  66. Pingback引用通告: bitly.com/3zaklyatie3

  67. Pingback引用通告: bitly.com/1dreykfilm

  68. Pingback引用通告: bitly.com/topgunmavericktopgun

  69. Pingback引用通告: bitly.com/flash2022

  70. Pingback引用通告: bitly.com/fantasticheskietvari3

  71. Pingback引用通告: bitly.com/wonderwoman1984hd

  72. Pingback引用通告: Human design

  73. Pingback引用通告: 1444

  74. Pingback引用通告: cleantalkorg2.ru

  75. Pingback引用通告: 232dfsad

  76. Pingback引用通告: cleantalkorg2.ru/sitemap.xml

  77. Pingback引用通告: join vk

  78. Pingback引用通告: vk login

  79. Pingback引用通告: svaty—7—sezon

  80. Pingback引用通告: svaty 7 sezon

  81. Pingback引用通告: svaty 7

  82. Pingback引用通告: tik tok

  83. Pingback引用通告: 666

  84. Pingback引用通告: The Revenant

  85. Pingback引用通告: 00-tv.com

  86. Pingback引用通告: 2021

  87. Pingback引用通告: D4

  88. Pingback引用通告: 777

  89. Pingback引用通告: link

  90. Pingback引用通告: 4569987

  91. Pingback引用通告: news news news

  92. Pingback引用通告: psy

  93. Pingback引用通告: psy2022

  94. Pingback引用通告: projectio-freid

  95. Pingback引用通告: kinoteatrzarya.ru

  96. Pingback引用通告: topvideos

  97. Pingback引用通告: video

  98. Pingback引用通告: afisha-kinoteatrov.ru

  99. Pingback引用通告: Ukrainskie-serialy

  100. Pingback引用通告: site

  101. Pingback引用通告: top

  102. Pingback引用通告: soderzhanki-3-sezon-2021.online

评论已关闭。