Modify a CListCtrl class with a complete color

Source: Internet
Author: User

In the process of using the CListCtrl control, we find it inconvenient to use, especially if you want to add a background color to the specified entry when using the "reporting" display mode, the set color function provided by the CListCtrl control only makes the control's interface look better. Cannot meet our requirements, we can not add a particular item or a few different colors to show the difference. Fortunately, many VC users in the transformation of CListCtrl class, making it more powerful to do a lot of work, developed a variety of inheriting classes to achieve this function, Sven Freitag is one of them. He issued a CListCtrl of the inheritance class Ccolorlistctrl to achieve the specified entry plus background color function, and free online to VC users, I collected in the source code of his source program, you can read the reader first.

The Ccolorlistctrl class sample code works as shown in the following illustration:

How to use the Ccolorlistctrl class:

1. Add the following documents to your project:

color.h
color.cpp
ColorListCtrl.h
ColorListCtrl.cpp

2. Add the ColorListCtrl.h description in the dialog header file, then use Ccolorlistctrl instead of CListCtrl to declare the member variable.

3, the specific use of the method, please see the sample code in the ColoredListCtrlDlg.cpp file.

Deficiencies in the Ccolorlistctrl class:

In the process of using the Ccolorlistctrl class, I realized the fun of adding the item color at random, but also found some deficiencies in it. Below I list the color.h and Color.cpp file codes for analysis. The color.h source code looks like this:

AUTHOR:SFR frydaysoft@gmx.de
#ifndef Afx_color_h__9fc7d36b_fc88_42fd_8daa_2f70016038ba__included_
#define Afx_color_h__9fc7d36b_fc88_42fd_8daa_2f70016038ba__included_
#include "Windows.h"
typedef enum
{
Def_background=0, Def_text, Def_selbackground, Def_seltext, Def_deselbackground, Def_deseltext,
Black,blue,green,cyan,red,
Mangenta,yellow,white,darkblue,darkgreen,
Bluegreen,brown,purpur,oliv,darkgray,
Lightgray,lightblue,darkwhite,middlegray
}
Item_color;
typedef struct
{
Char str[50];
Item_color Col;
}colorlist;
#define COLLIST_MAX 25
extern colorlist Collist[collist_max];
COLORREF getcolorref (Item_color lParam);
#endif
The color.cpp source code looks like this:
AUTHOR:SFR frydaysoft@gmx.de
#include "stdafx.h"
#include "Color.h"
ColorList collist[collist_max]=
{
{"Def_background", Def_background},
{"Def_text", Def_text},
{"Def_selbackground", Def_selbackground},
{"Def_seltext", Def_seltext},
{"Def_deselbackground", Def_deselbackground},
{"Def_deseltext", Def_deseltext},
{"Black", Black},
{"Blue", blue},
{"Green", green},
{"Cyan", cyan},
{"Red", Red},
{"Mangenta", Mangenta},
{"Yellow", yellow},
{"White", white},
{"Darkblue", Darkblue},
{"Darkgreen", Darkgreen},
{"Bluegreen", Bluegreen},
{"Brown", brown},
{"Purpur", Purpur},
{"Oliv", Oliv},
{"Darkgray", Darkgray},
{"Lightgray", Lightgray},
{"LightBlue", LightBlue},
{"Darkwhite", Darkwhite},
{"Middlegray", Middlegray}
};
COLORREF getcolorref (Item_color lParam)
{
Switch (LParam)
{
Case Def_background:return:: GetSysColor (Color_window); Break
Case Def_text:return:: GetSysColor (Color_windowtext); Break
Case Def_selbackground:return:: GetSysColor (Color_activecaption); Break
Case Def_seltext:return:: GetSysColor (Color_highlighttext); Break
Case Def_deselbackground:return:: GetSysColor (Color_inactivecaption); Break
Case Def_deseltext:return:: GetSysColor (Color_inactivecaptiontext); Break
Case Black:return RGB (0,0,0); Break Black
Case Blue:return RGB (0,0,255); Break Blue
Case Green:return RGB (0,255,0); Break Green
Case Cyan:return RGB (0,255,255); Break Cyan
Case Red:return RGB (255,0,0); Break Red
Case Mangenta:return RGB (255,0,255); Break Mangenta
Case Yellow:return RGB (255,255,0); Break Yellow
Case White:return RGB (255,255,255); White
Case Darkblue:return RGB (0,0,128); Break Dark-blue
Case Darkgreen:return RGB (0,128,0); Break Dark-green
Case Bluegreen:return RGB (0,128,128); Break Blue-green
Case Brown:return RGB (128,0,0); Break Brown
Case Purpur:return RGB (128,0,128); Break Purpur
Case Oliv:return RGB (128,128,0); Break Oliv
Case Darkgray:return RGB (128,128,128); Dark-gray
Case Lightgray:return RGB (192,192,192); Light-gray
Case Lightblue:return RGB (166,202,240); Light-blue
Case Darkwhite:return RGB (255,251,240); Dark-white
Case Middlegray:return RGB (160,160,164); Middle-gray
Default:return RGB (0,128,0); Break Dark-green
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.