function TfrmMain.MakeTrans(pngPath:
string; frm: TfrmMain): Boolean;
var
blendfunc : BLENDFUNCTION;
LngHeight : Cardinal;
LngWidth : Cardinal;
curWinLong : Integer;
img : Cardinal;
graphics : Cardinal;
winSize : TSize;
srcPoint : TPoint;
begin
Result := True;
try
DC := CreateCompatibleDC(frm.Canvas.Handle);
MainBitmap := CreateDIBSection(
DC, frm.Width, frm.Height, 32);
SelectObject(
DC, MainBitmap);
GdipCreateFromHDC(
DC, graphics);
GdipLoadImageFromFile(PWideChar(pngPath), img);
if img = 0
then
begin
result := False;
exit;
end;
GdipGetImageHeight(img, LngHeight);
GdipGetImageWidth(img, LngWidth);
GdipDrawImageRect(graphics, img, 0, 0, LngWidth, LngHeight);
curWinLong := GetWindowLong(frm.Handle, GWL_EXSTYLE);
SetWindowLong(frm.Handle, GWL_EXSTYLE, curWinLong
Or WS_EX_LAYERED);
SetWindowPos(frm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE
Or SWP_NOSIZE);
srcPoint.x := 0;
srcPoint.y := 0;
winSize.cx := frm.Width;
winSize.cy := frm.Height;
With blendFunc
do
begin
AlphaFormat := AC_SRC_ALPHA;
BlendFlags := 0;
BlendOp := AC_SRC_OVER;
SourceConstantAlpha := 255;
end;
GdipDisposeImage(img);
GdipDeleteGraphics(graphics);
UpdateLayeredWindow(frm.Handle, frm.Canvas.Handle,
nil, @winSize,
DC, @srcPoint, 0, @blendFunc, ULW_ALPHA);
except
Result := False;
end;
end;