Avatar of skink91
 asked on

TextOut to a DIB always in black


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);
      HBITMAP hOldBMP = (HBITMAP)SelectObject(dcTmp,m_dibWindow->GetBitmap());
      HFONT hOldFont = (HFONT)SelectObject(dcTmp,m_hFont);
      SelectObject(dcTmp, hOldFont);

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

System Programming

Avatar of undefined
Last Comment

8/22/2022 - Mon

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);

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

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.

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.)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question