Need help with GDI+ & Delphi (not .NET)

Can anybody point me to sample of using GDI+ with Delphi?

And is it true that GDI+ is a part of .NET framework? Can it be used alone, without 20+mb of .NET?

What i want -> draw a cute "icons" (like AveDesk do ;)) on desktop.

I think i need a transparent form/window and draw an image on it... Please, any advice :P

PS

Im sure i saw a post with code samples (by Ave or other devels...) but i cant find it anymore...

#253098

I'm doing small things with GDI+ and Delphi. I googled a bit and found a unit that imports all the function and classes offered by the library. No, there is no need for .NET ( IMO, big slow and heavy, and a bit c*appy ;) ), you just need the gdiplus dll to be somewhere on your system. I don't have the unit here, wait 9hrs :)

#253109

here we go: http://www.progdigy.com/ under the headers section you can find the gdiplus packages :)

#253183

procedure TfrmLeft.Redraw(NewWidth,NewHeight:Integer);

var

graphics: TGPGraphics;

bmp, img: TGPBitmap;

winLong:Cardinal;

ABlendFunction:Blendfunction;

AScreenDC,ASourceDC:HDC;

ASourcePosition,FPosition:TPoint;

FSize:TSize;

ABufferBitmap,AOldBitmapSelectedInCanvasDC :HBitmap;

FColorKey:TColor;

FFlags:DWORD;

s,h:Integer;

r:TRectF;

ih:Integer;

prefix:String;

tmp_bmp : TGPBitmap;

tmp_g : TGPGraphics;

brush:TGPTextureBrush;

begin

if AttachedTo <> nil then begin

if AttachedTo.Isactive then begin

prefix := '';

end else begin

prefix := 'inactive_';

end;

end else begin

prefix:='';

end;





winLong:=GetWindowLong(Handle,GWL_EXSTYLE);

winLong:= winLong or WS_EX_LAYERED;

SetWindowLong(Handle,GWL_EXSTYLE,winLong);





bmp:= TGPBitmap.Create(NewWidth,NewHeight);

graphics := TGPGraphics.Create(bmp);



h:= NewHeight;



//img:= TGPBitmap.Create(AttachedTo.GetSkinFolder()+'left_top.png');



//graphics.DrawImage(img,0,0,NewWidth,img.GetHeight);

//s:= img.GetHeight();

//h := h - s;

s:=0;



//img.Free();

img:= TGPBitmap.Create(AttachedTo.GetSkinFolder()+prefix+'left_bottom.png');

ih:=img.GetHeight();

graphics.DrawImage(img,0,NewHeight - Integer(ih),NewWidth,ih );

h := h - Integer(img.GetHeight());



img.Free();



img:= TGPBitmap.Create(AttachedTo.GetSkinFolder()+prefix+'left_middle.png');



brush := TGPTextureBrush.Create(img);



r.X := 0;

r.y := 0;

r.Width := NewWidth;

r.Height := h;

brush.ScaleTransform(1.0,1.0);



graphics.FillRectangle(brush,r);



brush.Free();



//tmp_bmp := TGPBitmap.Create(NewWidth,h);

//tmp_g := TGPGraphics.Create(tmp_bmp);

//tmp_g.DrawImage(img,0,0,NewWidth,h+3);



//tmp_g.Free();

img.Free();



//graphics.DrawImage(tmp_bmp,0,0,0,0,NewWidth,h,UnitPixel);

//tmp_bmp.Free();



AScreenDC := GetDC(0);



ASourcePosition.x := 0;

ASourcePosition.y := 0;



ABlendFunction.BlendOp := AC_SRC_OVER;

ABlendFunction.BlendFlags := 0;

ABlendFunction.SourceConstantAlpha := 255;

ABlendFunction.AlphaFormat := AC_SRC_ALPHA;



ASourceDC := CreateCompatibleDC(AScreenDC);



bmp.GetHBITMAP(0, ABufferBitmap);

AOldBitmapSelectedInCanvasDC := SelectObject(ASourceDC, ABufferBitmap);



FPosition.X := Left;

FPosition.Y := Top;

FSize.Width :=bmp.GetWidth();

FSize.Height := bmp.GetHeight();



FColorKey := RGB(255,0,255);

FFlags := ULW_ALPHA;



UpdateLayeredWindow(Handle, AScreenDC,@FPosition,

@FSize,

ASourceDC,

@ASourcePosition,

FColorKey,

@ABlendFunction,

FFlags

);





SelectObject(ASourceDC, AOldBitmapSelectedInCanvasDC);

DeleteObject(ABufferBitmap);

DeleteDC(ASourceDC);



ReleaseDC(0, AScreenDC);



graphics.Free();

bmp.Free();

end;

Here's a snippet.

#254114

Thanx guys :)

@dreadnaut

I found that site too :) but thank you very much

@AndreasV

Hey. You are all_capitals developer ;) --> DEVELOPER!!!

Thanx for sample. i'll try it.

#255538

damn ;) its work!!!

thank you very much Andreas!!!

i don't understand why it is not working in my realization... will dig it :) but now i can make a cutty window ;)

#255711

brush := TGPTextureBrush.Create(img);

why it promotes me that brush can not be assigned a value?

anyone could offer an easier code for this example, thx

#257762

Maybe you have wrong/incomplete GDI+ headers?

mine is from here: http://www.progdigy.com/ -> headers

#259619

I have tried and it still get some errors, i have given my codes as following

unit Unit1;



interface



uses

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

Dialogs, GDIPAPI,GDIPOBJ,DirectDraw,GDIPUTIL;



type

TForm1 = class(TForm)

private

{ Private declarations }

procedure Redraw(NewWidth,NewHeight:Integer);

public

{ Public declarations }

end;



var

Form1: TForm1;



implementation



{$R *.dfm}

procedure TForm1.Redraw(NewWidth,NewHeight:Integer);

var

graphics: TGPGraphics;

bmp,img: TGPBitmap;

winLong:Cardinal;

ABlendFunction:Blendfunction;

AScreenDC,ASourceDC:HDC;

ASourcePosition,FPosition:TPoint;

FSize:TSize;

ABufferBitmap,AOldBitmapSelectedInCanvasDC :HBitmap;

FColorKey:TColor;

FFlags:DWORD;

s,h:Integer;

r:TRectF;

ih:Integer;

prefix:String;

tmp_bmp : TGPBitmap;

tmp_g : TGPGraphics;

brush:TGPTextureBrush;

begin

winLong:=GetWindowLong(Handle,GWL_EXSTYLE);

winLong:= winLong or WS_EX_LAYERED;

SetWindowLong(Handle,GWL_EXSTYLE,winLong);

bmp:= TGPBitmap.Create(NewWidth,NewHeight);

graphics := TGPGraphics.Create(bmp);

h:= NewHeight;

s:=0;

img:= TGPBitmap.Create('./1.png');

ih:=img.GetHeight();

graphics.DrawImage(img,0,NewHeight - Integer(ih),NewWidth,ih );

h := h - Integer(img.GetHeight());

img.Free();

brush := TGPTextureBrush.Create(img);

r.X := 0;

r.y := 0;

r.Width := NewWidth;

r.Height := h;

brush.ScaleTransform(1.0,1.0);

graphics.FillRectangle(brush,r);

brush.Free();

img.Free();

AScreenDC := GetDC(0);

ASourcePosition.x := 0;

ASourcePosition.y := 0;

ABlendFunction.BlendOp := AC_SRC_OVER;

ABlendFunction.BlendFlags := 0;

ABlendFunction.SourceConstantAlpha := 255;

ABlendFunction.AlphaFormat := AC_SRC_ALPHA;

ASourceDC := CreateCompatibleDC(AScreenDC);

bmp.GetHBITMAP(0, ABufferBitmap);

AOldBitmapSelectedInCanvasDC := SelectObject(ASourceDC, ABufferBitmap);

FPosition.X := Left;

FPosition.Y := Top;

FSize.Width :=bmp.GetWidth();

FSize.Height := bmp.GetHeight();

FColorKey := RGB(255,0,255);

FFlags := ULW_ALPHA;

UpdateLayeredWindow(Handle, AScreenDC,@FPosition,

@FSize,

ASourceDC,

@ASourcePosition,

FColorKey,

@ABlendFunction,

FFlags

);

SelectObject(ASourceDC, AOldBitmapSelectedInCanvasDC);

DeleteObject(ABufferBitmap);

DeleteDC(ASourceDC);

ReleaseDC(0, AScreenDC);



graphics.Free();

bmp.Free();

end;



end.

error message is "undeclared identifier TRectF", how should i work with this?

#334897