Delphi 如何完整地捕捉窗口?

Delphi 如何完整地捕捉窗口?,delphi,Delphi,我在下面有一段代码,它捕获了一个特定的窗口,该窗口被成功捕获,但只显示了窗口的一部分 如何解决 多谢各位 procedure ScreenShotWindow; var c: TCanvas; r, t: TRect; h: THandle; Bild: TBitMap; begin c := TCanvas.Create; h := FindWindow(nil, 'Untitled - Notepad'); c.Handle := GetWindowDC(h);

我在下面有一段代码,它捕获了一个特定的窗口,该窗口被成功捕获,但只显示了窗口的一部分

如何解决

多谢各位

procedure ScreenShotWindow;
var
  c: TCanvas;
  r, t: TRect;
  h: THandle;
  Bild: TBitMap;
begin
  c := TCanvas.Create;
  h := FindWindow(nil, 'Untitled - Notepad');
  c.Handle := GetWindowDC(h);
  GetWindowRect(h, t);
  try
    r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
    Bild := TBitMap.Create;
    try
      Bild.Width  := t.Right - t.Left;
      Bild.Height := t.Bottom - t.Top;
      Bild.Canvas.CopyRect(r, c, t);
      Bild.SaveToFile('test'+ RandomPassword(10)+'.bmp');
    finally
      Bild.Free;
    end;
  finally
    ReleaseDC(0, c.Handle);
    c.Free;
  end;
end;

这里有很多不必要的、过于复杂的代码

这对我很有用:

procedure ScreenShotWindow;
var
  DC: HDC;
  wRect: TRect;
  Bmp: TBitmap;
  Width, Height: Integer;
  H: HWnd;
begin
  H := FindWindow(nil, 'Untitled - Notepad');
  if H = 0 then
    raise Exception.Create('FindWindow failed.');  // GetLastError would tell you why.
                                                   // I leave that to you to add if needed

  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);
      Bmp.SaveToFile('test' + RandomPassword(10) + '.bmp');
    finally
      Bmp.Free;
    end;
  finally
    ReleaseDC(H, DC);
  end;
end;