Solved

Changing background colour of List Box and text colour

Posted on 1998-06-26
1
210 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
1 Comment
 
LVL 4

Accepted Solution

by:
piano_boxer earned 50 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

11 Experts available now in Live!

Get 1:1 Help Now