Einzelnen Beitrag anzeigen

Benutzerbild von halinchen
halinchen

Registriert seit: 13. Jun 2006
508 Beiträge
 
Delphi 2007 Professional
 
#1

GetDC mit einer Komponente

  Alt 8. Mär 2007, 14:49
Hi!

Ich möchte in mein Programm eine Animation einer GroupBox einfügen.
Die GroupBox soll sich immer weiter verkleinern, bis die Höhe 0 ist und dann soll es die Werte ändern und dann die GruopBox wieder "ausfahren".
Das ist auch nicht mein Problem. Allerdings flimmert es. (Auch mit DoubleBuffered:=true).

Deswegen dachte ich mir, ich kopier das Bild der GroupBox und lass das Bild rein- und rausklappen.
Reinzu geht es. Aber rauszu nicht. Und zwar muss die GroupBox sichtbar sein damit sie "abfotografiert" werden kann.

Delphi-Quellcode:
procedure TfrmProduct.AnimateUp(Speed:Integer);
var
i:Integer;
begin
While img.Height > 0 do begin
    img.Height:=img.Height-1;
    For i := 0 to Speed do Application.ProcessMessages;
end;
end;

procedure TfrmProduct.AnimateDown(Speed:Integer);
var
i:Integer;
begin
While img.Height < frmProduct.ClientHeight - 5 do begin
    img.Height:=img.Height+1;
    For i := 0 to Speed do Application.ProcessMessages;
end;
end;

procedure TfrmProduct.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
bmp := TBitmap.Create;
GetImage(bmp);
img.Picture.bitmap.Assign(NIL);
img.picture.bitmap := bmp;
img.stretch := false;
img.Left := GroupBox1.Left;
img.Top := GroupBox1.Top;
img.Width := GroupBox1.Width;
img.height := GroupBox1.height;
img.Visible := true;
GroupBox1.Visible := false;
AnimateUp(10000);
Case TControl(Sender).Tag of
...
end;
Image1.Picture.Bitmap.Assign(NIL);
Image1.Picture.Bitmap.Height := 48;
ImageList1.GetBitmap(TControl(Sender).Tag,Image1.Picture.Bitmap);
GetImage(bmp);
img.Picture.bitmap.Assign(NIL);
img.picture.bitmap := bmp;
img.height := 0;
bmp.Free;
AnimateDown(10000);
img.Visible := false;
GroupBox1.Visible := true;
end;


procedure TfrmProduct.GetImage(var bmp:TBitmap);
var
 DCanvas: TCanvas;
 DHandle: HWND;
begin
 DHandle:=GetDC(GroupBox1.Handle);
 if DHandle=0 then begin
    exit;
 end;
 DCanvas := TCanvas.Create;
 DCanvas.Handle := DHandle;
 bmp := Tbitmap.Create;
 bmp.Assign(NIL);
 bmp.Height := GroupBox1.Height;
 bmp.Width := GroupBox1.Width;
 bmp.Canvas.CopyRect(Rect(0,0,GroupBox1.Width,GroupBox1.Height),DCanvas,Rect(0,0,GroupBox1.Width,GroupBox1.Height));
 DCanvas.Free;
end;
Ich könnte nun die GroupBox anzeigen lassen und ProcessMessages aufrufen, damit sie gezeichnet wird: Aber dann erscheint immer kurz die GroupBox und geht dann weg und dann klappt es auf.
Wie mach ich es besser?
  Mit Zitat antworten Zitat