如何完全捕获窗口?

时间:2017-02-02 18:08:00

标签: delphi

我有下面的代码捕获一个特定的窗口,窗口是用成功捕获的,但只显示了窗口的一部分。

如何解决?

谢谢。

correct

enter image description here

1 个答案:

答案 0 :(得分:4)

你那里有很多不必要的,过于复杂的代码。

这对我有用:

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;