title: Win32 C++ BitBlt Transparency
body: <p><strong>UPDATED LOOK AT BOTTOM OF THIS POST</strong>
  What I am doing is trying to use one Black and White bitmap, to lay a background bitmap on the white, and the tile overlay on the black. The problem I am having is adding the overlay.</p>
  
  <p><img src="https://i.stack.imgur.com/2uFP3.jpg" alt="This is all the parts"></p>
  
  <p>and this is my BitBlt() code, this code produces #5.</p>
  
  <pre><code>hOldBitmap = (HBITMAP)SelectObject(hdcMem, bitmap.hbmBackground); // #2
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCCOPY); 
  
  hOldBitmap = (HBITMAP)SelectObject(hdcMem, bitmap.hbmMap); // #1
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCAND);
  
  hOldBitmap = (HBITMAP)SelectObject(hdcMem, bitmap.hbmMapOverlay); // #4
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCAND);   
  </code></pre>
  
  <p>I am unsure about using the same "hOldBitmp", but it seems to do the same thing either way.</p>
  
  <p>The transparent blt function would not fully suffice here, either.</p>
  
  <p>Thanks.</p>
  
  <p><strong>NEW</strong></p>
  
  <p>I have been having trouble combining and rastoring. I can somewhat handle DC's and bitmaps, but this is one thing I cant figure out how to do... Creating memory dcs, and dcs to hold a bitmap, dc for another bitmap, then bitblt to the mem. I think...</p>
  
  <p>Heres my redundant code I have at the moment. Really I am needing help with pseudo code, how to combine the bitmaps... how many DC's are necessary, etc.. </p>
  
  <p>buffer.getBufferDC() is the main DC that displays on the screen.</p>
  
  <pre><code>HDC hdc = GetDC(hWnd);
  HDC hdcMem = CreateCompatibleDC(hdc);
  HDC hdcMem2 = CreateCompatibleDC(hdc);
  HDC hdcMem3 = CreateCompatibleDC(hdc);
  HDC hdcMem4 = CreateCompatibleDC(hdc);
  HBITMAP hbmMem3 = CreateCompatibleBitmap(hdc, WINDOW_WIDTH, WINDOW_HEIGHT);
  HBITMAP hbmMem4 = CreateCompatibleBitmap(hdc, WINDOW_WIDTH, WINDOW_HEIGHT);
  ReleaseDC(hWnd, hdc);
  
  // Copy the map and clean the hdcMem
  HBITMAP hbmOld;
  hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmMap);
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCCOPY);    
  SelectObject(hdcMem, hbmOld);
  hbmOld = (HBITMAP)SelectObject(hdcMem2, bitmap.hbmBackground);
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem2, 0, 0, SRCAND);    
  SelectObject(hdcMem2, hbmOld);     
  
  hbmOld = (HBITMAP)SelectObject(hdcMem3, bitmap.hbmMapOverlay);
  hbmOld = (HBITMAP)SelectObject(hdcMem4, bitmap.hbmMap);
  BitBlt(hdcMem3, 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem4, 0, 0, SRCINVERT);
  
  BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem3, 0, 0, SRCPAINT);     
  //hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmMap);
  //BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCPAINT);    
  //SelectObject(hdcMem, hbmOld);
  
  
  //hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmMapOverlay);
  //BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCAND);    
  //SelectObject(hdcMem, hbmOld);    
  
  DeleteDC(hdcMem);
  DeleteDC(hdcMem2);
  DeleteDC(hdcMem3);
  DeleteDC(hdcMem4);
  </code></pre>