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:
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.