I have tried this function using BitBlt:
function PACaptureWindowToTIEBitmap(AWinHandle: HWND): TIEBitmap;
var
WindowDC: HDC;
WindowRect: TRect;
CaptureRect: TRect;
begin
// Create the TIEBitmap that will hold the screenshot of the window
Result := TIEBitmap.Create;
// Get the device context (DC) of the window
WindowDC := GetWindowDC(AWinHandle);
try
// Get the dimensions of the window, including non-client areas
GetWindowRect(AWinHandle, WindowRect);
CaptureRect := Rect(0, 0, WindowRect.Right - WindowRect.Left, WindowRect.Bottom - WindowRect.Top);
// Prepare the TIEBitmap to match the window size
Result.Allocate(CaptureRect.Right - CaptureRect.Left, CaptureRect.Bottom - CaptureRect.Top);
// Copy from the window's DC to the TIEBitmap
BitBlt(Result.Canvas.Handle, 0, 0, CaptureRect.Right, CaptureRect.Bottom, WindowDC, 0, 0, SRCCOPY);
finally
ReleaseDC(AWinHandle, WindowDC);
end;
end;
But even that does not capture the menu!