您现在的位置:首页 >> 图形媒体 >> 图形媒体 >> 内容

Delphi编写截屏活动窗口成位图

时间:2011/9/3 15:00:38 点击:

  核心提示:600) this.width = 600;'>procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;var w,h : in...

600) this.width = 600;">

procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;
var
   w,h : integer;
   DC : HDC;
   hWin : Cardinal;
   r : TRect;
begin
   if activeWindow then
   begin
     hWin := GetForegroundWindow;
     dc := GetWindowDC(hWin) ;
     GetWindowRect(hWin,r) ;
     w := r.Right - r.Left;
     h := r.Bottom - r.Top;
   end
   else
   begin
     hWin := GetDesktopWindow;
     dc := GetDC(hWin) ;
     w := GetDeviceCaps (DC, HORZRES) ;
     h := GetDeviceCaps (DC, VERTRES) ;
   end;

   try
    destBitmap.Width := w;
    destBitmap.Height := h;
    BitBlt(destBitmap.Canvas.Handle,
           0,
           0,
           destBitmap.Width,
           destBitmap.Height,
           DC,
           0,
           0,
           SRCCOPY) ;
   finally
    ReleaseDC(hWin, DC) ;
   end;
end;

用法示例: 

var
   b:TBitmap;
begin
  b := TBitmap.Create;
  try
    ScreenShot(TRUE, b) ;
    Image1.Picture.Bitmap.Assign(b) ;
  finally
    b.FreeImage;
    FreeAndNil(b) ;
  end;

完整代码已经打包下载



迅雷专用高速下载

作者:站长 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号