首页 > 代码库 > Delphi异形窗口之PNG
Delphi异形窗口之PNG
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 implementation13 procedure AlienForm_PNGFromFile(AForm : TForm; AFileName : String);14 var15 wic : TWICImage;16 begin17 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 var24 wic : TWICImage;25 r : TResourceStream;26 begin27 if Instance = 0 then28 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 var38 ptDst, ptSrc: TPoint;39 Size: TSize;40 BlendFunction: TBlendFunction;41 bmp : TBitmap;42 begin43 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 begin71 AlienForm_PNGFromFile(Form2, ‘E:\未标题.png‘);72 end;
Delphi异形窗口之PNG
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。