title: Off-screen drawing GDI+
body: <p>I have a problem - I need to draw two png files, one on the other. When I do it usual way, there is a "blinking" effect (first image overdraws the second one for small time period). I use GDI+ library and my WM_PAINT handling looks like this:</p>
  
  <pre><code>case WM_PAINT:
  {
      PAINTSTRUCT ps; 
      HDC hdc = BeginPaint( hwnd, &amp; ps );
      displayImage(firstImage, hwnd);
      displayImage(secondImage, hwnd);
      EndPaint( hwnd, &amp; ps );
      break;
  }
  </code></pre>
  
  <p>displayImage function:</p>
  
  <pre><code>void displayImage(HBITMAP mBmp, HWND mHwnd)
  {
      RECT myRect;
      BITMAP bm;
      HDC screenDC, memDC;
      HBITMAP oldBmp;
      BLENDFUNCTION bf;
  
      GetObject(mBmp, sizeof(bm), &amp;bm);
  
      bf.BlendOp = AC_SRC_OVER;
      bf.BlendFlags = 0;
      bf.SourceConstantAlpha = 0xff;
  
      bf.AlphaFormat = AC_SRC_ALPHA;
  
      screenDC = GetDC(mHwnd);
      GetClientRect(mHwnd, &amp;myRect);
  
      if (mBmp == NULL)
          FillRect(screenDC, &amp;myRect, WHITE_BRUSH);
  
      else
      {
          memDC = CreateCompatibleDC(screenDC);
          oldBmp = (HBITMAP)SelectObject(memDC, mBmp);
          AlphaBlend (screenDC, 0, 0, myRect.right,myRect.bottom, memDC, 0, 0, bm.bmWidth,bm.bmHeight, bf);
          SelectObject(memDC, oldBmp);
          DeleteDC(memDC);
          ReleaseDC(mHwnd, screenDC);
      }
  }
  </code></pre>
  
  <p>Loading files to variables:</p>
  
  <pre><code>HBITMAP mLoadImg(WCHAR *szFilename)
  {
     HBITMAP result=NULL;
  
     Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
     bitmap-&gt;GetHBITMAP(NULL, &amp;result);
     delete bitmap;
     return result;
  }
  
  
  firstImage = mLoadImg(L"data\\img\\screen.png");
  secondImage = mLoadImg(L"data\\img\\screen2.png");
  </code></pre>
  
  <p>I've heard that I should do a off-screen drawing. How should that look like?</p>