Link to home
Start Free TrialLog in
Avatar of skink91
skink91

asked on

TextOut to a DIB always in black

Hi.

I'm having a problem with a DIB that I've selected into a DC to do a TextOut call to.  It seems that the text is always BLACK no matter what I do... and I need the text to be white.  Any suggestions?  Thanks.  (sample code below)

      HDC hDC = GetDC(hMainWnd);
      HDC dcTmp = CreateCompatibleDC(hDC);
      ReleaseDC(hMainWnd,hDC);
      HBITMAP hOldBMP = (HBITMAP)SelectObject(dcTmp,m_dibWindow->GetBitmap());
      HFONT hOldFont = (HFONT)SelectObject(dcTmp,m_hFont);
      SetTextColor(dcTmp,RGB(255,255,255));
      SetBkMode(dcTmp,TRANSPARENT);
        TextOut(dcTmp,5,350,"330",strlen("330"));
      SelectObject(dcTmp, hOldFont);
      SelectObject(dcTmp,hOldBMP);
      GdiFlush();
      DeleteDC(dcTmp);

      // at this point i BLT the DIB to a memory DC and Invalidate the main window...

Avatar of skink91
skink91

ASKER

sorry, I forgot to mention that the value returned by 'm_dibWindow->GetBitmap()' is an HBITMAP generated by the following call:

      m_hBitmap = CreateDIBSection(hDC,(LPBITMAPINFO)m_lpBitmapInfoHeader, DIB_PAL_COLORS,(LPVOID *)&m_lpBits,NULL,0);
Avatar of skink91

ASKER

also, the DIB is 8bpp and uses a indexed palette...
      
BitBlt might not be able to reconcile your 8-bit DIB with the screen, or specifying COLORREFs may be invalid for 8-bit bitmaps.

Why not just use a DDB?  CreateCompatibleBitmap.
Or maybe no compatible palette is realised?  Try using an ordinary indexed palette: 8-bit with DIB_RGB_COLORS as the flag.  You should only use DIB_PAL_COLORS when you know what's going on with the palette in your DC.
Avatar of skink91

ASKER

I needed my DIB calls to be as optimized as humanly possible for the quantity of graphic/redraws I'm doing (hence the DIB, and DIB_PAL_COLORS palette setup.)
ASKER CERTIFIED SOLUTION
Avatar of Alkali_Guy
Alkali_Guy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial