PDA

View Full Version : form transparent...



pixin
23-08-2009, 04:37 PM
hi, how can make a delphi form as an alpha mask sprite and hide the delphi form and all stuff?? i want to create a person or something moving on windows desktop with mouse and when you click some thing appear..any one has an idea how to remove de form background??? thanks in advance..

Andreaz
23-08-2009, 05:45 PM
Well, cross posting doesnt really help.

However, doing it with D3D/OpenGL in the realm of Phoenix is not that easy, i suppose you have to take a screenshot and use that as a texture.

For making a standard VCL form transparent check the following:

http://delphi.about.com/cs/adptips1999/a/bltip0899_5.htm

Traveler
23-08-2009, 09:57 PM
This is not a specific Phoenix question. I have moved it to the Graphics section.

User137
24-08-2009, 01:53 PM
This is very old code of mine, it basically keeps drawing straight horizontal lines (to create invisible region) until it meets pixel that is not colored as transparent. Transparent color is taken from coord 0,0 of bitmap.
function CreateBitmapRgn(c: TCanvas; Width,Height: Word): HRGN;
var p: array[0..30000] of TPoint;
vertex: array[0..10000] of integer;
trc,i,j,pm: integer; drawing: boolean;
begin
pm:=-1; drawing:=false; trc:=c.Pixels[0,0];
for j:=0 to height-1 do
for i:=0 to width-1 do
if (c.Pixels[i,j]=trc) or (i>=width-1) then begin
if drawing then begin
drawing:=false;
p[pm*3+1]:=point(i,j); p[pm*3+2]:=point(i,j+1);
end;
end else if not drawing then begin
drawing:=true;
inc(pm); vertex[pm]:=3; p[pm*3]:=point(i,j);
end;
result:=CreatePolyPolygonRgn(p,vertex,pm+1,WINDING );
end;

After that use SetWindowRgn() function with region given from this and you can make even human shaped form but it might be too slow like this if you want to animate it.

To original question; "No" not DelphiX, Phoenix, SDL or any other graphics library can make form transparent. Window is handled by operating system that in this case might be Windows, hence use Windows API.

pixin
24-08-2009, 02:06 PM
well thanks, i think it's very easier to do it with flash.

User137
24-08-2009, 04:27 PM
well thanks, i think it's very easier to do it with flash.

Don't know about flash, but i guess some ways are possible as seen there:
http://www.wave-access.com/Public_en/projects/ZINC_Transparent_Projector.aspx

Wizard
24-08-2009, 05:56 PM
Actually, it's very easy...

Start a new app and place the following in the formCreate:

MakeInvisible(form1);

Add the following procedure:

procedure MakeInvisible(const Form: TCustomForm);
var
hRgn: Cardinal;
i: Integer;
begin
with Form do
begin
BorderStyle := bsNone;
hRgn := CreateRectRgn(0, 0, 0, 0);
for i := 0 to ControlCount - 1 do
with Controls[i].BoundsRect do
CombineRgn(hRgn, hRgn, CreateRectRgn(Left, Top, Right, Bottom), RGN_OR);
SetWindowRgn(handle, hRgn, True);

end;
end;

Then in form onPaint:

PaintDesktop(Canvas.Handle);

That's it, your form is invisible ;)

User137
24-08-2009, 08:31 PM
That code only leaves rectangular areas if i see right?

Wizard
25-08-2009, 06:43 AM
User137: I'm not sure what you mean, it makes the whole form transparent. It doesn't leave any rectangular areas.

User137
25-08-2009, 12:28 PM
User137: I'm not sure what you mean, it makes the whole form transparent. It doesn't leave any rectangular areas.

Yes it does. You use CreateRectRgn for each visible control but it doesn't look for non-rectangular images.


for i := 0 to ControlCount - 1 do
with Controls[i].BoundsRect do
CombineRgn(hRgn, hRgn, CreateRectRgn(Left, Top, Right, Bottom), RGN_OR);

I will see if i could optimize my function maybe... if theres time.