How to draw text with transparent color using WinAPI? Usually I used SetBkMode (hDC, TRANSPARENT), but now I need to use a double buffer. Thus, the images are drawn correctly, but the text does not draw correctly (with a black background).
case WM_PAINT: { hDC = BeginPaint(hWnd, &paintStruct); SetBkMode(hDC, TRANSPARENT); HDC cDC = CreateCompatibleDC(hDC); HBITMAP hBmp = CreateCompatibleBitmap(hDC, width, height); HANDLE hOld = SelectObject(cDC, hBmp); HFONT hFont = (HFONT)SelectObject(hDC, font); SetTextColor(cDC, color); SetBkMode(cDC, TRANSPARENT); TextOut(cDC, 0, 0, text, wcslen(text)); SelectObject(cDC, hFont); BitBlt(hDC, 0, 0, width, height, cDC, 0, 0, SRCCOPY); SelectObject(cDC, hOld); DeleteObject(hBmp); DeleteDC(cDC); EndPaint(hWnd, &paintStruct); return 0; }
source share