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

x
?
Solved

Changing background colour of List Box and text colour

Posted on 1998-06-26
1
Medium Priority
?
237 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 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

Industry Leaders: 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

971 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