|
这是PNG异形透明窗体的范例,根据其他语言修改而来。
talince QQ:408153576
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, GDIPAPI;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MakeTrans ;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
MoveI: Boolean=False; //无窗体移动
x1,y1,x2,y2: Integer; //无窗体移动
m_Blend: BLENDFUNCTION;
m_hdcMemory: HDC;
hdcScreen: HDC;
hObject: HDC;
hBMP: HBITMAP;
sizeWindow: SIZE;
// rct: TRECT;
ptSrc: TPOINT;
_Graphics: GpGraphics;
implementation
{$R *.lfm}
{ TForm1 }
function UpdateLayeredWindow(Handle: THandle; hdcDest: HDC; pptDst: PPoint; _psize: PSize;
hdcSrc: HDC; pptSrc: PPoint; crKey: COLORREF; pblend: PBLENDFUNCTION; dwFlags: DWORD): Boolean; stdcall;
external 'user32.dll';
procedure TForm1.FormCreate(Sender: TObject);
var
GpInput: TGdiplusStartupInput ;
GpOutput: PGdiplusStartupOutput;
token: ULONG;
begin
GpInput.DebugEventCallback := nil;
GpInput.SuppressBackgroundThread := False;
GpInput.SuppressExternalCodecs := False;
GpInput.GdiplusVersion := 1;
GdiplusStartup(token, @GpInput,GpOutput);
MakeTrans;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//无窗体移动
if (Button = mbLeft) then
begin
MoveI:= True;
x1 := X ;
y1 := Y;
end
else
begin
Close;
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if MoveI then
begin
x2 := X - x1 + Self.Left;
y2 := Y - y1 + Self.Top;
Self.SetBounds(x2,y2,Self.Width ,Self.Height);
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
MoveI:= False;
end;
procedure TForm1.MakeTrans; //画图
var
img: GpImage;
imgS: GpImage;
lngHeight: cardinal;
lngWidth: cardinal;
lngHeightS: cardinal;
lngWidthS: cardinal;
// tempBI: BITMAPINFO;
curWinLong: LONG;
begin
m_Blend.BlendOp := AC_SRC_OVER; // the only BlendOp defined in Windows 2000
m_Blend.BlendFlags := 0; // Must be zero
m_Blend.AlphaFormat := AC_SRC_ALPHA; //This flag is set when the bitmap has an Alpha channel
m_Blend.SourceConstantAlpha := 255;
GdipLoadImageFromFile('.\skin\flower\flower.png',img);
GdipLoadImageFromFile('.\skin\flower\flower_s.png ',imgS);
GdipGetImageHeight(img, lngHeight);
GdipGetImageWidth(img, lngWidth);
GdipGetImageHeight(imgS, lngHeightS);
GdipGetImageWidth(imgS, lngWidthS);
hdcScreen := GetDC(0);
m_hdcMemory := CreateCompatibleDC(hdcScreen);
sizeWindow.cx := lngWidth;
sizeWindow.cy := lngHeight;
// GetWindowRect(Handle, rct);
hBMP := CreateCompatibleBitmap(hdcScreen, lngWidth, lngHeight);
SelectObject(m_hdcMemory, hBMP);
GdipCreateFromHDC(m_hdcMemory, _Graphics) ;
GdipDrawImageRect(_graphics, img, 0, 0, lngWidth, lngHeight);
GdipDeleteGraphics(_graphics);
GdipCreateFromHDC(m_hdcMemory, _Graphics) ;
GdipRotateWorldTransform(_Graphics,50,MatrixOrderAppend); //设置旋转角度
GdipTranslateWorldTransform(_Graphics,-lngWidthS/2, -lngHeightS/2,MatrixOrderPrepend);
GdipTranslateWorldTransform(_Graphics,lngWidth/ 2, lngHeight/ 2, MatrixOrderAppend);
GdipDrawImageRect(_graphics, imgS, 0, 0, lngWidthS, lngHeightS);
GdipDeleteGraphics(_graphics);
curWinLong := GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED);
GdipDisposeImage(img);
GdipDisposeImage(imgs);
GdipDeleteGraphics(_graphics);
ptSrc.x := 0;
ptSrc.y := 0;
UpdateLayeredWindow(Handle, hdcScreen, nil,@sizeWindow, m_hdcMemory, @ptSrc, 0, @m_Blend, ULW_ALPHA);
//Release resources
SelectObject(m_hdcMemory,hObject);
DeleteObject(hBMP);
DeleteObject(hObject);
end;
end. |
|