I'm drawing text into a DIB section off-screen bitmap, which is 32bit deep and uses the alpha channel (ARGB). I draw pixels directly to memory. Then, I create a Gdiplus Graphics object, pass my memory DC to it, and draw text using Graphics::DrawString. This works fine under normal circumstances. Over Remote Desktop, however, the text rendered is completely transparent, i.e. instead of drawing any colour pixels, you can see through where the text is. Does anyone know why this is so, and how to fix it??
Here's my drawString routine:
void SplashScreen::drawString (MyString &ivText, Gdiplus::RectF &r,
Gdiplus::ARGB c, Gdiplus::StringAlignment align, Gdiplus::Font &fnt,
Gdiplus::Graphics &gfx)
{
Gdiplus::StringFormat fmt;
fmt.SetAlignment (align);
Gdiplus::SolidBrush brush (c);
wchar_t *wstr = new wchar_t [ivText.length()+1];
std::mbstowcs (wstr, ivText.cstr(), ivText.length()+1);
gfx.DrawString (wstr, ivText.length(), &fnt, r, &fmt, &brush);
delete wstr;
}
And that's how I create the DIB:
BITMAPV5HEADER bhd;
memset (&bhd, 0, sizeof (bhd));
bhd.bV5Size = sizeof (BITMAPV5HEADER);
bhd.bV5Width = nWidth;
bhd.bV5Height = -nHeight; // negative height indicates top-down DIB
bhd.bV5Planes = 1;
bhd.bV5BitCount = 32;
bhd.bV5Compression = BI_BITFIELDS;
bhd.bV5RedMask = 0x00FF0000;
bhd.bV5GreenMask = 0x0000FF00;
bhd.bV5BlueMask = 0x000000FF;
bhd.bV5AlphaMask = 0xFF000000;
m_pBuf = NULL;
m_hBmp = ::CreateDIBSection (m_hDC, (BITMAPINFO *) &bhd, DIB_RGB_COLORS,
(void **) &m_pBuf, NULL, 0);
if (m_hBmp == NULL || m_pBuf == NULL)
{
// error...
}
HGDIOBJ oldObj = ::SelectObject (m_hDC, m_hBmp);
if (oldObj == NULL)
{
// error...
}
After drawing text into the DIB, I do
gfx.Flush (Gdiplus::FlushIntentionSync);
EDIT: It may also be of interest to you that the window where the DIB is finally drawn into is a WS_EX_LAYERED window. It's a splash screen that shows when the application starts, and is slowly faded in and out using a timer and the following method:
void SplashScreen::setWindowTransparency (int nAlpha)
// @param nAlpha: 255 is opaque, 0 is fully transparent.
{
HWND hwnd = getHwnd();
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = nAlpha;
blend.AlphaFormat = AC_SRC_ALPHA;
BOOL bResult = ::UpdateLayeredWindow (hwnd, NULL, NULL, NULL, NULL,
NULL, RGB (0, 0, 0), &blend, ULW_ALPHA);
}