Solved

Coloring a list control and not the controls within it

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

Accepted Solution

by:
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;
  GetClientRect(&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
}
0
 
LVL 44

Expert Comment

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

Assisted Solution

by:alb66
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.



0
 
LVL 44

Expert Comment

by:AndyAinscow
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
0
 
LVL 19

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
configuration management 2 100
Change owner from userA to server Local Administrators 7 51
modThree challenge 4 64
changeXy challenge 13 57
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

23 Experts available now in Live!

Get 1:1 Help Now