如何使用 WinAPI 绘制具有透明颜色的文本?通常我使用 SetBkMode(hDC, TRANSPARENT),但现在我需要使用双缓冲。这样,图像绘制正确,但文本绘制不正确(黑色背景)。
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;
}