频道分类

Delphi 对非活动窗口进行屏幕截图

作者:admin 来源: 日期:2020/9/15 21:15:52 人气: 标签:

 
function WindowSnap(windowHandle: HWND; bmp: TBitmap): boolean;
var
  r: TRect;
  user32DLLHandle: THandle;
  printWindowAPI: function(sourceHandle: HWND; destinationHandle: HDC;
    nFlags: UINT): BOOL; stdcall;
begin
  result := False;
  user32DLLHandle := GetModuleHandle(user32) ;
  if user32DLLHandle <> 0 then
  begin
    @printWindowAPI := GetProcAddress(user32DLLHandle, 'PrintWindow');
    if @printWindowAPI <> nil then
    begin
      GetWindowRect(windowHandle, r) ;
      bmp.Width := r.Right - r.Left;//www.delphitop.com
      bmp.Height := r.Bottom - r.Top;
      bmp.Canvas.Lock;
      try
        result := printWindowAPI(windowHandle, bmp.Canvas.Handle, 0) ;
      finally
        bmp.Canvas.Unlock;
      end;
    end;
  end;
end; (*WindowSnap*)



procedure TForm2.Button1Click(Sender: TObject);

begin
Image1.Picture:=nil;
WindowSnap(Self.Handle, Image1.Picture.Bitmap) ;
Image1.Refresh;

end;

上一篇:Delphi 合并文件下一篇:没有资料