[help] PNG transparent window(UpdateLayeredWindow)!

Hi!

I´m trying to display a transparent PNG File on my form with some common controls, like a button or an edit box.

The problem is that i use UpdateLayeredWindow to give a bitmap with alpha

transparency to my main window. And this is everything I see. My child

controls are not painted.

how can I use some common controls ("BUTTON", "EDIT", etc) or even other

more complex like a html view or other activx control?

Is there a way to force them to paint themselfs in a given DC? Or maybe to

make them ignore the fact that their parent is a layered window?

Please help me with a solution or someting!

Thanks!

#259054

unit Unit1;



interface



uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs,gdipapi, gdipobj, ExtCtrls;



type

TForm1 = class(TForm)

Timer1: TTimer;

procedure FormCreate(Sender: TObject);

Procedure MoveForm(var M:TWMNCHITTEST); Message WM_NCHITTEST;

procedure FormDestroy(Sender: TObject);



private

{ Private declarations }

public

{ Public declarations }

end;

const

WS_EX_LAYERED = $80000;

LWA_COLORKEY = 1;

LWA_ALPHA = 2;

ULW_COLORKEY = 1;

ULW_ALPHA = 2;

ULW_OPAQUE = 4;



var

Form1: TForm1;

bmp, old_bmp : HBITMAP;

DC : HDC;

bitmap:array[1..15] of tgpbitmap;



Function UpdateLayeredWindow(hWnd : HWND;

hdcDst : HDC; pptDst : PPoint; psize : PSize;

hdcSrc : HDC; pptSrc : PPoint;

crKey : COLORREF;

pblend : PBlendFunction;

dwFlags : DWORD): BOOL; stdcall;



implementation



{$R *.dfm}

Function UpdateLayeredWindow; external 'user32.dll';



Procedure TForm1.MoveForm (var M:TWMNCHITTEST);

begin

inherited;

M.Result:=HTCAPTION;

end;



procedure TForm1.FormCreate(Sender: TObject);

var

pt1, pt2 : TPoint;

sz : TSize;

bf : TBlendFunction;

begin

if SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or

WS_EX_LAYERED) = 0 then ShowMessage(SysErrorMessage(GetLastError));



bitmap[1]:=tgpbitmap.Create('c:1.png');

form1.Width:=bitmap[1].GetWidth;

form1.Height:=bitmap[1].GetHeight;



pt1 := Point(left, top);

pt2 := Point(0, 0);

sz.cx := bitmap[1].GetWidth;

sz.cy := bitmap[1].GetHeight;

bf.BlendOp := AC_SRC_OVER;

bf.BlendFlags := 0;

bf.SourceConstantAlpha := $ff;

bf.AlphaFormat := AC_SRC_ALPHA;



DeleteObject(bmp);

bitmap[1].GetHBITMAP(0,bmp);

DeleteDC(DC);

DC := CreateCompatibleDC(Canvas.Handle);

old_bmp := SelectObject(DC, bmp);

UpdateLayeredWindow(Handle, Canvas.Handle, @pt1, @sz, DC, @pt2,0, @bf,ULW_ALPHA);

end;



procedure TForm1.FormDestroy(Sender: TObject);

begin

SelectObject(DC, old_bmp);

DeleteObject(bmp);

DeleteDC(DC);

bitmap[1].Free;

end;





end.

how can I put some control on this png image? My controls(labels,buttons) are not painted.

#259055

Layered Windows cannot have controls or child windows on them. You could try to play with windowless controls and and paint them on a mem-dc and then pass that to UpdateLayeredWindow(...).

#259056

Layered Windows cannot have controls or child windows on them. You could try to play with windowless controls and and paint them on a mem-dc and then pass that to UpdateLayeredWindow(...).

What is windowless controls ?

I have posted the code, did you see it?

#259057

Layered Windows cannot have controls or child windows on them. You could try to play with windowless controls and and paint them on a mem-dc and then pass that to UpdateLayeredWindow(...).

Can you please give us an example how to do that with a button ro something?

caue I have the same problem!

Thanx

#264044