0

Prior to Windows10 (and possibly W8) we could use a simple BitBlt to capture a window:

function WindowSSToBmp(h: hWnd; var b: TBitmap): Boolean;
Var DC: HDC;
    r: TRect;
begin
  Windows.GetWindowRect(h,r);
  b.Width  := r.Right - r.Left;
  b.height := r.Bottom - r.Top;
  DC  := GetWindowDC(GetDesktopWindow);
  BitBlt(b.Canvas.Handle,0,0,b.Width,b.height,DC,r.Left,r.Top,SRCCOPY);
  ReleaseDC(0,DC);
  Result := True;
end;

but ever since W10 this adds a few extra pixels around the window, probably as the rect includes part of the shadow outline at the edges so it captures a part of the other windows beneath it:

enter image description here

What's the correct way to do this in W10? Note that if you use Alt+PrtScr it gets the correct real visible area of the window without the extra edges.

hikari
  • 3,393
  • 1
  • 33
  • 72
  • 1
    The reopen vote blows my mind! Accepted answer at dupe explains precisely what is wrong. Use `DwmGetWindowAttribute` with `DWMWA_EXTENDED_FRAME_BOUNDS` to avoid the back compat shims and it's all good. What is wrong with people in this tag? – David Heffernan Jun 05 '17 at 08:22
  • Sorry, Dwm works perfectly. – hikari Jun 05 '17 at 13:17
  • 1
    Indeed it does. You should give that answer an up-vote. Sadly, after I marked this as a dupe, that answer was downvoted! Probably the same person as voting to reopen. Oh well. – David Heffernan Jun 05 '17 at 13:21

0 Answers0