procedure SwitchToThisWindow(hWnd:Thandle;fAltTab:boolean);stdcall;external 'User32.dll';

-------------------------

 

GetWindowRect(h1, R);
try
bmp.Free;
except

end;
Bmp := TBitmap.Create;
bmp.SetSize(r.Width,r.Height);
Bmp.Width := r.Width ;
Bmp.Height := r.Height;
SwitchToThisWindow(h1,true);
keybd_event(VK_SNAPSHOT,1,0,0);
application.ProcessMessages;sleep(111); application.ProcessMessages;sleep(111); application.ProcessMessages;sleep(111); application.ProcessMessages;sleep(111); application.ProcessMessages;sleep(111);
if (ClipBoard.HasFormat(CF_PICTURE)) or
(ClipBoard.HasFormat(CF_METAFILEPICT)) then
begin
pic := TPicture.Create;
pic.Assign(ClipBoard);
X := pic.Width;
Y := pic.Height;
bmp.Width := X;
bmp.Height := Y;
bmp.Canvas.Draw(0, 0, pic.Graphic);
pic.Free;
end;
if (ClipBoard.HasFormat(CF_BITMAP)) then
begin
bmp.Assign(ClipBoard);
end;