Solved

Changing background colour of List Box and text colour

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 64
twoTwo  challenge 35 103
post4 challenge 28 100
Thin secure Windows 10 5 98
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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