Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing background colour of List Box and text colour

Posted on 1998-06-26
1
Medium Priority
?
233 Views
Last Modified: 2013-11-20
hello All

I am wondering if it is possible to change the background colour and text colour in a list box using MFC.  I tried to look at the CListBox class and there seems to be no member functions that could do this.

I look forward to your reply.

Best Regards

Asif

0
Comment
Question by:AsifMughal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
piano_boxer earned 200 total points
ID: 1318466
It is possible.

You need to handle the WM_CTLCOLOR message in the parent dialog. In this message handler you can change the default colors.

Here is an example:

HBRUSH CTestAppDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    static HBRUSH hMyBrush = NULL;

    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      
    if(CTLCOLOR_LISTBOX==nCtlColor)
    {
        pDC->SetTextColor(RGB(255,0,0));
        pDC->SetBkColor(RGB(0,255,0));
        if(!hMyBrush)
            hMyBrush = ::CreateSolidBrush(RGB(0,0,255));

        return hMyBrush
    }
    return hbr;
}

This will make the text red, background of text green, and clientarea of control blue.
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

719 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