title: How to create Gdiplus::Bitmap from CDC
body: <p>I am trying to create a <code>Gdiplus::Bitmap</code> from a device context. The function I use is:</p>
  
  <pre><code>Bitmap bitmap((HBITMAP)myDC.GetCurrentBitmap(), (HPALETTE)myDC.GetCurrentPalette());
  </code></pre>
  
  <p>...but when I draw the bitmap on the screen, all I see is a black rectangle. I think I'm using the <code>Bitmap</code> constructor wrong, because in docs it's written: </p>
  
  <blockquote>
    <p>Do not pass to the GDI+ Bitmap::Bitmap constructor a GDI bitmap or a
    GDI palette that is currently (or was previously) selected into a
    device context.</p>
  </blockquote>
  
  <p>But I have no idea how to go around this. Another approach I tried is using:</p>
  
  <blockquote>
    <p>To capture the preexisting image from a window, a Windows Graphics Device Interface (GDI) function such as BitBlt() or StretchBlt() would have to be used to copy the image from the screen to a memory bitmap. This memory bitmap could then be used in the overloaded Bitmap constructor, which takes an HBITMAP as a parameter.</p>
  </blockquote>
  
  <p>But I couldn't achieve this either.</p>