Link to home
Start Free TrialLog in
Avatar of yingkit
yingkit

asked on

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)
Avatar of hubdog
hubdog

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;
ASKER CERTIFIED SOLUTION
Avatar of hubdog
hubdog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yingkit

ASKER

Instead of using stretchblt, bitblt would be more appropriate.
BitBlt(Image1.Canvas.Handle,0,0,Image1.Width,Image1.Height,
winDC,0,0,SRCCOPY);