Pateman
Pateman

Reputation: 2757

Full screenshot of a window

I am using this code to create a screenshot of a specified window (either active or not).

function WndScreen(const h: HWND; const bmp: TBitmap): boolean;
var
  Src, Dst: HDC;
  R: TRect;
  Width, Height: Integer;
  B: HBITMAP;
  Old: HGDIOBJ;
begin
  Src := GetDC(h);
  GetWindowRect(h, R);
  Width := R.Right - R.Left;
  Height := R.Bottom - R.Top;
  Dst := CreateCompatibleDC(Src);
  B := CreateCompatibleBitmap(Src, Width, Height);
  Old := SelectObject(Dst, B);
  BitBlt(Dst, 0, 0, Width, Height, Src, 0, 0, SRCCOPY);
  SelectObject(Dst, Old);
  DeleteDC(Dst);
  ReleaseDC(h, Src);

  bmp.Width := Width;
  bmp.Height := Height;
  bmp.Handle := B;

  DeleteObject(B);
end;

Now let's say that the window has a combobox. When I click on the combobox and expand the list, the list content is not included in my screenshot.

Do you know of any method to create a full window screenshot?

Upvotes: 1

Views: 550

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596236

Have a look at the PrintWindow() function instead of using BitBlt() directly. Despite its name, PrintWindow() can be used for capturing screenshots to a bitmap, it is not limited to just printing.

Upvotes: 2

Related Questions