title: How to draw text using CDC with transparent background on CBitmap?
body: <p>I have the following code which sort of works provided you mask out the pink pixels however what I actually want is transparent bits like a PNG file so that I can avoid alpha blending issues and the need mask out a specific color everywhere the bitmap will be used.</p>
  
  <pre><code>CClientDC dc(pWnd);
  CDC memDC;
  
  if(!memDC.CreateCompatibleDC(&amp;dc))
     return NULL;
  
  CRect bitmapRect;
  bitmapRect.SetRectEmpty();
  
  CFont* pOldFont = memDC.SelectObject(pWnd-&gt;GetFont());
  CSize fontSize = memDC.GetTextExtent(imageText);
  
  bitmapRect.right = fontSize.cx;
  bitmapRect.bottom = fontSize.cy;
  
  CBitmap bitmap;
  if(!bitmap.CreateCompatibleBitmap(&amp;dc, bitmapRect.Width(), bitmapRect.Height()))
     return NULL;
  
  CBitmap* pOldMemDCBitmap = memDC.SelectObject(&amp;bitmap);
  
  memDC.FillSolidRect(&amp;bitmapRect, RGB(255,0,255));
  //memDC.SetBkMode(TRANSPARENT); // doesn't work
  //memDC.SetBkColor(TRANSPARENT); // doesn't work
  memDC.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
  
  //memDC.DrawText(imageText, bitmapRect, DT_TOP|DT_LEFT|DT_NOCLIP); // same difference
  memDC.TextOut(0, 0, imageText);
  
  memDC.SelectObject(pOldMemDCBitmap);
  memDC.SelectObject(pOldFont);
  memDC.DeleteDC();
  
  CImageList bmImage;
  bmImage.Create(bitmapRect.Width(), bitmapRect.Height(), ILC_COLOR32|ILC_MASK, 0, 1);
  // this masks out the pink but for some windows blends edges of text causing pink text instead of black!
  bmImage.Add(&amp;bitmap, RGB(255,0,255));
  </code></pre>
  
  <p>Is just the bug filled beast that is MFC misbehaving or am I missing something?</p>