Transparent static text label

Hi
I'm trying to write a small dialog application. I have a static label control on the dialog and I want to make its background transparent, but I'm not having any success.

Here's the code I'm trying at the moment

      CStatic* pStaticText = (CStatic*)GetDescendantWindow(IDC_STATIC_COMPANY);
            
      if (pStaticText != NULL)
      {
            DWORD style = pStaticText->GetStyle();


            if (SetWindowLong(pStaticText->m_hWnd, GWL_STYLE, style | SS_NOTIFY) == 0)
                  MessageBox("Unable to set window style");
            
            CDC* pStaticDC = pStaticText->GetDC();

            if (pStaticDC != NULL)
            {                  
                  
                  COLORREF bob = 0xFFFFFF;
                  
                  pStaticDC->SetBkMode(OPAQUE);
                  
                  if (pStaticDC->SetBkColor(bob) == 0x80000000)                  
                        MessageBox("Unable to set back colour");
                  
                  pStaticDC->SetBkColor(bob);

                  CString fontName = "Times New Roman";

                  CFont staticFont;            
                  if (staticFont.CreateFont(1000,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,fontName) != TRUE)
                        MessageBox("Unable to create font");
            
                  pStaticText->SetFont(&staticFont,TRUE);

                  
            }else
            {
                  MessageBox("Unable to get DC");
            }
      }
      else
      {
            MessageBox("Unable to get window");
      }


I've been trying to change the font size as well! In this code I'm simply trying to change the background colour just to see if anything happens.  I haven't done any VC++ programming for a very long time) (It easy in VB!!!)

Thanks in advance

~Ian
microdrainageAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

olgatCommented:
You can  override OnCtlColor message handler in your dialog as follows:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor!=CTLCOLOR_STATIC)
// Normal processing: don't do anything
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Set background mode transparent with null brush
      pDC->SetBkMode(TRANSPARENT);
      pDC->SetTextColor(someColor);

      return  m_clHollowBrush;
}

where hollow brush was created as
m_clHollowBrush.CreateStockObject(NULL_BRUSH)

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.