• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi异形窗口之PNG

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 

 

 1 //1.单元内容
 2 unit UnitAlienForm;
 3 interface
 4 uses
 5   Windows, Forms, Classes, Graphics;
 6 //从文件加载PNG
 7 procedure AlienForm_PNGFromFile(AForm : TForm; AFileName : String);
 8 //从资源加载PNG
 9 procedure AlienForm_PNGFromResource(AForm : TForm; ResName : String; ResType : PWideChar; Instance : HINST = 0);
10 //从图像对象加载
11 procedure AlienForm_PNGFromGraphic(AForm : TForm; AGraphic : TGraphic);
12 implementation
13 procedure AlienForm_PNGFromFile(AForm : TForm; AFileName : String);
14 var
15   wic : TWICImage;
16 begin
17   wic := TWICImage.Create;
18   wic.LoadFromFile(AFileName);
19   AlienForm_PNGFromGraphic(AForm, wic);
20   wic.Free;
21 end;
22 procedure AlienForm_PNGFromResource(AForm : TForm; ResName : String;ResType : PWideChar; Instance : HINST);
23 var
24   wic : TWICImage;
25   r : TResourceStream;
26 begin
27   if Instance = 0 then
28     Instance := HInstance;
29   r := TResourceStream.Create(Instance, ResName, ResType);
30   wic := TWICImage.Create;
31   wic.LoadFromStream(r);
32   AlienForm_PNGFromGraphic(AForm, wic);
33   wic.Free;
34   r.Free;
35 end;
36 procedure AlienForm_PNGFromGraphic(AForm : TForm; AGraphic : TGraphic);
37 var
38   ptDst, ptSrc: TPoint;
39   Size: TSize;
40   BlendFunction: TBlendFunction;
41   bmp : TBitmap;
42 begin
43   bmp := TBitmap.Create;
44   bmp.Assign(AGraphic);
45   ptDst := Point(AForm.Left, AForm.Top);
46   ptSrc := Point(0, 0);
47   Size.cx := AGraphic.Width;
48   Size.cy := AGraphic.Height;
49   BlendFunction.BlendOp := AC_SRC_OVER;
50   BlendFunction.BlendFlags := 0;
51   BlendFunction.SourceConstantAlpha := $FF; // 透明度
52   BlendFunction.AlphaFormat := AC_SRC_ALPHA;
53   SetWindowLong(AForm.Handle, GWL_EXSTYLE, GetWindowLong(AForm.Handle,
54       GWL_EXSTYLE) or WS_EX_LAYERED);
55   UpdateLayeredWindow(AForm.Handle,
56      AForm.Canvas.Handle,
57      @ptDst,
58      @Size,
59      bmp.Canvas.Handle,
60      @ptSrc,
61      0,
62      @BlendFunction,
63      ULW_ALPHA);
64   bmp.Free();
65 end;
66 end.
67 
68 //2.调用方法
69 procedure TForm2.FormCreate(Sender: TObject);
70 begin
71   AlienForm_PNGFromFile(Form2, 'E:\未标题.png');
72 end;

 

http://www.cnblogs.com/FKdelphi/p/5843038.html

 

 

 1 //1.单元内容
 2 unit UnitAlienForm;
 3 interface
 4 uses
 5   Windows, Forms, Classes, Graphics;
 6 //从文件加载PNG
 7 procedure AlienForm_PNGFromFile(AForm : TForm; AFileName : String);
 8 //从资源加载PNG
 9 procedure AlienForm_PNGFromResource(AForm : TForm; ResName : String; ResType : PWideChar; Instance : HINST = 0);
10 //从图像对象加载
11 procedure AlienForm_PNGFromGraphic(AForm : TForm; AGraphic : TGraphic);
12 implementation
13 procedure AlienForm_PNGFromFile(AForm : TForm; AFileName : String);
14 var
15   wic : TWICImage;
16 begin
17   wic := TWICImage.Create;
18   wic.LoadFromFile(AFileName);
19   AlienForm_PNGFromGraphic(AForm, wic);
20   wic.Free;
21 end;
22 procedure AlienForm_PNGFromResource(AForm : TForm; ResName : String;ResType : PWideChar; Instance : HINST);
23 var
24   wic : TWICImage;
25   r : TResourceStream;
26 begin
27   if Instance = 0 then
28     Instance := HInstance;
29   r := TResourceStream.Create(Instance, ResName, ResType);
30   wic := TWICImage.Create;
31   wic.LoadFromStream(r);
32   AlienForm_PNGFromGraphic(AForm, wic);
33   wic.Free;
34   r.Free;
35 end;
36 procedure AlienForm_PNGFromGraphic(AForm : TForm; AGraphic : TGraphic);
37 var
38   ptDst, ptSrc: TPoint;
39   Size: TSize;
40   BlendFunction: TBlendFunction;
41   bmp : TBitmap;
42 begin
43   bmp := TBitmap.Create;
44   bmp.Assign(AGraphic);
45   ptDst := Point(AForm.Left, AForm.Top);
46   ptSrc := Point(0, 0);
47   Size.cx := AGraphic.Width;
48   Size.cy := AGraphic.Height;
49   BlendFunction.BlendOp := AC_SRC_OVER;
50   BlendFunction.BlendFlags := 0;
51   BlendFunction.SourceConstantAlpha := $FF; // 透明度
52   BlendFunction.AlphaFormat := AC_SRC_ALPHA;
53   SetWindowLong(AForm.Handle, GWL_EXSTYLE, GetWindowLong(AForm.Handle,
54       GWL_EXSTYLE) or WS_EX_LAYERED);
55   UpdateLayeredWindow(AForm.Handle,
56      AForm.Canvas.Handle,
57      @ptDst,
58      @Size,
59      bmp.Canvas.Handle,
60      @ptSrc,
61      0,
62      @BlendFunction,
63      ULW_ALPHA);
64   bmp.Free();
65 end;
66 end.
67 
68 //2.调用方法
69 procedure TForm2.FormCreate(Sender: TObject);
70 begin
71   AlienForm_PNGFromFile(Form2, 'E:\未标题.png');
72 end;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi-IOCP学习笔记一====从零开始学习IOCP发布时间:2022-07-18
下一篇:
编写一个单独的WebServiceforDelphi发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap