Solved

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

Posted on 2003-10-27
3
932 Views
Last Modified: 2006-11-17
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
Comment
Question by:jbeichler
3 Comments
 
LVL 3

Accepted Solution

by:
freewell earned 125 total points
ID: 9639375
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
debug as  junit test 4 73
countClumps  challenge 10 111
factory design pattern vs abstract factoy design pattern 2 100
wordsFront challenge 8 84
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to implement Singleton Design Pattern in Java.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now