Coloring a list control and not the controls within it

Posted on 2006-11-30
Last Modified: 2013-11-20
How do i change the default color of a list control to a specific color of my choice.
Question by:Anisha
  • 3
  • 2
LVL 44

Accepted Solution

AndyAinscow earned 125 total points
ID: 18044678
Make your own class based on a list control  (class wizard will help you)

Trap the WM_ERASEBKGND message

BOOL CMyListCtrl::OnEraseBkgnd(CDC* pDC)
  CRect rc;
  pDC->FillSolidRect(RGB(0, 0, 128));  //change the values to give the colour you want
  return TRUE;   //IMPORTANT else it will not be changed
LVL 44

Expert Comment

ID: 18044825
correction -
  pDC->FillSolidRect(&rc, RGB(0, 0, 128));  //change the values to give the colour you want
LVL 19

Assisted Solution

alb66 earned 125 total points
ID: 18052007
To change the window background color you can use SetBkColor( RGB( ..., ..., ... ))
To change the text background color you can use SetTextBkColor( RGB( ..., ..., ... ))
To change the text color you can use SetTextColor( RGB( ..., ..., ... ))
All the functions above are methods of the CListCtrl class.

LVL 44

Expert Comment

ID: 18372959
OnEraseBkgnd is a simple way to do it (Coloring a list control and not the controls within it) and stop any nasty flickering
LVL 19

Expert Comment

ID: 18450667
CListCtrl already has all the methods Anisha need.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 106
Separate into files by filename 12 75
maxBlock challenge 30 111
zeroFront challenge 7 79
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. …
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

15 Experts available now in Live!

Get 1:1 Help Now