You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何对屏幕外不可见窗口进行连续截图?

如何对屏幕外不可见窗口进行连续截图?

我编写了如下Pascal代码,起初似乎可用,但仅能捕获第一帧,当目标窗口更新时,截图仍停留在第一帧。是否有其他实现方法?

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function ActiveCaption: string;
var
  Handle: THandle;
  Len: LongInt;
  Title: string;
begin
  Result := '';
  Handle := GetForegroundWindow;
  if Handle <> 0 then
  begin
    Len := GetWindowTextLength(Handle) + 1;
    SetLength(Title, Len);
    GetWindowText(Handle, PChar(Title), Len);
    ActiveCaption := TrimRight(Title);
  end;
end;

procedure ScreenShotWindow;
var
  DC: HDC;
  wRect: TRect;
  Bmp: TBitmap;
  Width, Height: Integer;
  H: HWnd;
  title: array[0..MAX_PATH]of char;
begin
  H := FindWindow(nil, PWideChar(ActiveCaption));  
  if H = 0 then
    Exit;

  DC := GetWindowDC(H);
  try
    Bmp := TBitmap.Create;
    try
      GetWindowRect(H, wRect);
      Width := wRect.Right - wRect.Left;
      Height := wRect.Bottom - wRect.Top;
      Bmp.SetSize(Width, Height);
      BitBlt(Bmp.Canvas.Handle, 0, 0, Width, Height, DC, 0, 0, SRCCOPY);
      Form1.Canvas.Draw(0, 0, Bmp);
    finally
      Bmp.Free;
    end;
  finally
    ReleaseDC(H, DC);
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   ScreenShotWindow;
end;

end.

编辑补充:
我仍希望找到可行方案,否则这可能是系统限制:

引用Remy:“如果窗口不在屏幕上,Windows不会对其进行实际渲染。”

内容的提问来源于stack exchange,提问作者JOTA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 23:57:28