Capture a window's screen

Hi,
How can I capture a window's screen and save it as a bitmap if I only know the caption of that window?
(ie. similar as pressing Alt-PrintScreen in Windows)
(D2)
yingkitAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hubdogConnect With a Mentor Commented:
for example:
procedure TForm1.Button1Click(Sender: TObject);
var
  Winrect:TRect;
  windc:hdc;
  winhandle:THandle;
begin
      winhandle:=FindWindow(nil, 'windowcaption');
      windc:=getdc(winhandle);
      GetWindowRect(winhandle,Winrect);
      stretchBlt(Image1.Canvas.Handle,  0,0,Image1.Width,Image1.Height,
             winDC, 0, 0,winrect.right-winrect.left,winrect.bottom-winrect.top, SRCCOPY);
       releasedc(winhandle,windc);
end;
0
 
hubdogCommented:
for example:
procedure TForm1.Button1Click(Sender: TObject);
var
  Winrect:TRect;
  windc:hdc;
  winhandle:THandle;
begin
      winhandle:=FindWindow(nil, '¼ÆËãÆ÷');
      windc:=getdc(winhandle);
      GetWindowRect(winhandle,Winrect);
      stretchBlt(Image1.Canvas.Handle,  0,0,Image1.Width,Image1.Height,
             winDC, 0, 0,winrect.right-winrect.left,winrect.bottom-winrect.top, SRCCOPY);
       releasedc(winhandle,windc);
end;
0
 
yingkitAuthor Commented:
Instead of using stretchblt, bitblt would be more appropriate.
BitBlt(Image1.Canvas.Handle,0,0,Image1.Width,Image1.Height,
winDC,0,0,SRCCOPY);
0
All Courses

From novice to tech pro — start learning today.