title: Delphi Active Window Screenshot
body: <p>I am trying to add capture screenshot of active window using this code</p>
  
  <pre><code>procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;
   var
      w,h : integer;
      DC : HDC;
      hWin : Cardinal;
      r : TRect;
   begin
      if activeWindow then
      begin
        hWin :=  GetForegroundWindow;
        dc := GetWindowDC(hWin) ;
        GetWindowRect(hWin,r) ;
        w := r.Right - r.Left;
        h := r.Bottom - r.Top;
      end
      else
      begin
        hWin := GetForegroundWindow;
        dc := GetDC(hWin) ;
        w := GetDeviceCaps (DC, HORZRES) ;
        h := GetDeviceCaps (DC, VERTRES) ;
      end;
  
      try
       destBitmap.Width := w;
       destBitmap.Height := h;
       BitBlt(destBitmap.Canvas.Handle,
              0,
              0,
              destBitmap.Width,
              destBitmap.Height,
              DC,
              0,
              0,
              SRCCOPY) ;
      finally
       ReleaseDC(hWin, DC) ;
      end;
   end;
  </code></pre>
  
  <p>And in Button1 i use :</p>
  
  <pre><code>var
    path:string;
    b:TBitmap;
  begin
     path:= ExtractFilePath(Application.ExeName) + '/Screenshot/';
     b := TBitmap.Create;
     try
       ScreenShot(TRUE, b) ;
       b.SaveToFile(path + 'Screenshot_1.png');
     finally
       b.FreeImage;
       FreeAndNil(b) ;
     end;
  end;
  </code></pre>
  
  <p>it works good only problem is it not capture title bar :(</p>
  
  <p>Here is Full Active window view :</p>
  
  <p><img src="https://i.stack.imgur.com/iuBH0.png" alt="enter image description here"></p>
  
  <p>And Here is what i get from that code </p>
  
  <p><img src="https://i.stack.imgur.com/T6Z4L.png" alt="enter image description here"></p>
  
  <p>Where am i doing wrong ??</p>