PNG profiled window

Source: Internet
Author: User

A colleague demonstrated a. NET PNG-shaped windows. It's pretty. So I want to show off with Delphi.

There are a lot of information about Delphi using PNG to do abnormity window. All are loaded with PNG images using Gdiplus or tpngimage components.

Fortunately, Delphi packaged Microsoft's Iwicimagingfactory interface, so that the work of PNG processing will be given to the operating system to do.

The function is very simple altogether a few lines, the key is Updatelayeredwindow.

With the Delphi2010 provided by the Iwicimagingfactory interface packaging, this time the PNG processing to Microsoft's operating system, a little bit of a problem. Other versions of Delphi can only be packaged for Iwicimagingfactory, Can handle it as well. But the Delphi2010 is the most convenient. No control, no extra stuff.

The code is as simple as this:)

Unit Yxform;

Interface

Uses

Windows, Forms, Classes, Graphics;

// Load from File PNG

procedure Yxfromfile(aform:tform; Afilename: String);

// Load from Resource PNG

procedure Yxfromresource(aform:tform; Resname: String; Restype:pwidechar; Instance:hinst = 0);

// loading from an Image object

procedure Yxfromgraphic(aform:tform; Agraphic:tgraphic);

Implementation

procedure Yxfromfile(aform:tform; Afilename: String);

Var

Wic:twicimage;

Begin

WIC:= twicimage. Create;

WIC. LoadFromFile(afilename);

Yxfromgraphic(aform, WIC);

WIC. Free;

End ;

procedure Yxfromresource(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);

Yxfromgraphic(aform, WIC);

WIC. Free;

R. Free;

End ;

procedure Yxfromgraphic(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; // Transparency

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 .

It's easy to use, for example:

Ff:=tform2.create (self);//Form2 refers to the new window, please modify it as appropriate.
Yxfromfile (FF, ' c:/a.png ');

Ff. Show;

It's also easy to implement animations. Just keep Yxfromfile (ff, ' c:/a.png '); Call a set of actions PNG.

The effect is as follows:

PNG profiled window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.