捕捉整个桌面的图片

捕捉整个桌面的图片 但不捕捉自己这个窗体
 

procedure TForm2.Button3Click(Sender: TObject);
var
  Bitmap: Tbitmap;
  BitmapCanvas: TCanvas;
  dc: HDC;
  DeskTopWidth,DeskTopHeight:Integer;
begin
  DeskTopWidth := Screen.Width;
  DeskTopHeight :=Screen.Height;

  Panel1.Width :=DeskTopWidth;
  Panel1.Height :=DeskTopHeight;

  Hide;
  Sleep( 200);
  Bitmap := TBitmap.Create;
   With Bitmap do
   begin
    Width := DeskTopWidth;
    Height := DeskTopHeight;
    DC := GetDC( 0);

    BitmapCanvas := TCanvas.Create;
    BitmapCanvas.Handle := DC;

    Canvas.CopyRect(Rect( 0, 0,DeskTopWidth, DeskTopHeight), BitmapCanvas,Rect( 0, 0, DeskTopWidth, DeskTopHeight));
    BitmapCanvas.Free;
    ReleaseDC( 0, DC);

    Image1.Picture.Bitmap := Bitmap;
    Image1.Width := Width;
    Image1.Height := Height;
    Free;
   end;
  Show;
  SetForegroundWindow(Handle);

end;




你可能感兴趣的:(图片)