后台截图函数

function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';  
procedure TForm1.btn3Click(Sender: TObject);
var
  bmp : TBitmap;
  wnd : cardinal;
  rec : TRect;
begin
   wnd := FindWindow(nil, '计算器');
   GetWindowRect(wnd, rec);
   bmp := TBitmap.Create;
   try
     bmp.Width := rec.Right - rec.Left;
     bmp.Height := rec.Bottom - rec.Top;
     bmp.PixelFormat := pf24bit;
     PrintWindow(wnd, bmp.Canvas.Handle, 0);
     img1.Picture.Bitmap:=bmp;
   finally
     bmp.Free;
  end;
end;
posted on 2011-03-10 18:13  飘啊飘的  阅读(341)  评论(0编辑  收藏  举报