Transparent static text label

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;
                  if (pStaticDC->SetBkColor(bob) == 0x80000000)                  
                        MessageBox("Unable to set back colour");

                  CString fontName = "Times New Roman";

                  CFont staticFont;            
                        MessageBox("Unable to create font");

                  MessageBox("Unable to get DC");
            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

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

olgatConnect With a Mentor Commented:
You can  override OnCtlColor message handler in your dialog as follows:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
// Normal processing: don't do anything
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Set background mode transparent with null brush

      return  m_clHollowBrush;

where hollow brush was created as

All Courses

From novice to tech pro — start learning today.