Solved

Changing background colour of List Box and text colour

Posted on 1998-06-26
1
222 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 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

751 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