Solved

Coloring a list control and not the controls within it

Posted on 2006-11-30
10
188 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 169
substring method in java 1 137
sum28 challenge 31 117
Increment column based of a FK 8 53
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

730 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