Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 994
  • Last Modified:

Having a problem setting a listbox's background as transparent using MFC's SetBkMode( ) in function OnCtlColor( )

I have set up an OnCtlColor( ) that is entered upon the initial drawing of a listbox control but fails to set it as transparent.  (I know this because I can see it in this function using the debugger under Visual C++.)  Later I want to write some text to this listbox and I can successfully change the font but can't make the background transparent so it shows up gray like the dialog box is.

It seems that I should be repainting/redrawing something after I put new text into this listbox control but I can't seem to figure out how to do it.

My purpose is to write some text in a font of my choice to the Dialog box so it has the background of the box itself rather than being with a white background.  Perhaps there is an easier way to do this.
0
jbeichler
Asked:
jbeichler
1 Solution
 
freewellCommented:
Create a solid brush which has the system color same as COLOR_3DFACE (dialog color).


class CAboutDlg : public CDialog
{
public:
      CAboutDlg();
      CBrush m_BrushList;
...
}

BOOL CAboutDlg::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here
      m_BrushList.CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
...
}

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      
      // TODO: Change any attributes of the DC here
      if(pWnd->GetDlgCtrlID()==IDC_LIST1)
      {
            pDC->SetBkMode(TRANSPARENT);
            hbr=(HBRUSH)m_BrushList;
      }

      // TODO: Return a different brush if the default is not desired
      return hbr;
}
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now