title: Convert PrintWindow to BitBlt to capture screenshot of a specific window
body: <p>I have a C++ program to capture the screenshot of a specific window and save it using the following code</p>
  
  <pre><code> int main()
   {
     GdiplusStartupInput gdiplusStartupInput;
     ULONG_PTR gdiplusToken;
     GdiplusStartup(&amp;gdiplusToken, &amp;gdiplusStartupInput, NULL);
  
     RECT rc;
     HWND hwnd = FindWindow(NULL,TEXT("Window Title Here"));
     if(hwnd == NULL)
     {
        cout&lt;&lt;"Can't Find Window";
        return 0;
     }
  
      GetClientRect(hwnd,&amp;rc);
  
      HDC hdcscreen = GetDC(NULL);
      HDC hdc = CreateCompatibleDC(hdcscreen);
  
      HBITMAP hbmp = CreateCompatibleBitmap(hdcscreen,rc.right - rc.left,rc.bottom - rc.top);
  
      SelectObject(hdc,hbmp);
  
      PrintWindow(hwnd,hdc,NULL);
  
      BitmapToJpg(hbmp,rc.right - rc.left,rc.bottom-rc.top); //Function to convert hbmp bitmap to jpg
  
      DeleteDC(hdc);
      DeleteObject(hbmp);
      ReleaseDC(NULL,hdcscreen);
   }
  </code></pre>
  
  <p>This code works for many of the windows, but for some of the windows, the output is a black image with correct width and height. On searching I found a solution to use <code>BitBlt()</code>. But I cannot figure out how to replace <code>PrintWindow()</code> with <code>BitBlt()</code> and output to a <code>HBITMAP</code>. Help Need</p>