Einzelnen Beitrag anzeigen

Benutzerbild von halinchen
halinchen

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

Re: GetDC mit einer Komponente

  Alt 9. Mär 2007, 17:30
Ich habs:
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(100000);
Case TControl(Sender).Tag of
0:begin
  Label1.Caption := L1_0;
  Label2.Caption := L2_0;
  end;
1:begin
  Label1.Caption := L1_1;
  Label2.Caption := L2_1;
  end;
2:begin
  Label1.Caption := L1_2;
  Label2.Caption := L2_2;
  end;
3:begin
  Label1.Caption := L1_3;
  Label2.Caption := L2_3;
  end;
end;
Image1.Picture.Bitmap.Assign(NIL);
Image1.Picture.Bitmap.Height := 48;
ImageList1.GetBitmap(TControl(Sender).Tag,Image1.Picture.Bitmap);
GroupBox1.Visible := true;
repaint;
GetImage(bmp);
GroupBox1.Visible := false;
img.Picture.bitmap.Assign(NIL);
img.picture.bitmap := bmp;
img.height := 0;
AnimateDown(100000);
img.Visible := false;
GroupBox1.Visible := true;
bmp.Free;
end;

procedure TfrmProduct.FormCreate(Sender: TObject);
begin
{frmProduct.DoubleBuffered := true;
GroupBox1.DoubleBuffered := true;}
 //Muss false sein, sonst sieht man während der Animation kurz die große GroupBox.
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.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));

end;
Durch das Repaint sieht man komischerweise die immernoch ausgeklappte GroupBox während der Animation nicht.
Einziger Nachteil: Wenn man das Programm hinter ein anderes Fenster setzt, kopiert es nicht die GroupBox in bmp, sondern den Teil des Screen, wo die GroupBox wäre.
  Mit Zitat antworten Zitat