![]() |
Desktop Development »
List Controls »
Custom Draw
Intermediate
License: The Code Project Open License (CPOL)
XListCtrl - A custom-draw list control with subitem formattingBy Hans DietrichA custom-draw list control with support for subitem colors, bold font, progress bars, and checkboxes. |
VC6Win2K, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
The use of list controls is becoming very common now, and is used by many apps with the need for some sort of list display. I have used list controls in many projects, and naturally have developed my own classes to display different colors, fonts, and progress bars in list control.
Recently I needed a list control with a checkbox like Hotmail. With a list like Hotmail you have checkbox in column header, and checkboxes in each subitem in that column. To set a check in every subitem, you check the checkbox in the column header. Similarly, if you uncheck one of the subitems, then the checkbox in the column header also gets unchecked.
The new CXListCtrl list control class supports these features:
The demo project provides a sample app that shows what the various features look like. Press the Start button and the list control is filled with data.

To integrate XListCtrl into your own app, you first need to decide if you want to include XListCtrl code into your own exe (using XListCtrl static link library), or if you want to link to XListCtrl DLL. Using DLL version of XListCtrl makes sense if you plan to use XListCtrl in several apps. The XListCtrl DLL is an MFC extension DLL, so your app must also be MFC-based.
If you plan to use and distribute DLL version of XListCtrl, do not put DLL in Windows directory. This could cause conflicts with other apps that use XListCtrl, and some future version of XListCtrl may not be compatible with the one that you distribute.
To use static XListCtrl library, define symbol XLISTCTRLLIB_STATIC before including header file XListCtrl.h. Otherwise, DLL version of XListCtrl will be linked to your app. Regardless of which version you link with, you must change your app's build environment as follows:


Using symbols _AFXDLL, XLISTCTRLLIB_STATIC, _DEBUG, and _UNICODE, the following code in XListCtrl.h automatically determines which XListCtrl library to link to your app:
#ifndef XLISTCTRLLIB_NOAUTOLIB
#if defined _AFXDLL && !defined XLISTCTRLLIB_STATIC
// MFC shared DLL with XListCtrl shared DLL
#ifdef _UNICODE
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlDDDU.lib")
#pragma message("Automatically linking with XListCtrlDDDU.lib")
#else
#pragma comment(lib,"XListCtrlDDRU.lib")
#pragma message("Automatically linking with XListCtrlDDRU.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlDDDA.lib")
#pragma message("Automatically linking with XListCtrlDDDA.lib")
#else
#pragma comment(lib,"XListCtrlDDRA.lib")
#pragma message("Automatically linking with XListCtrlDDRA.lib")
#endif
#endif
#elif defined _AFXDLL && defined XLISTCTRLLIB_STATIC
// MFC shared DLL with XListCtrl static lib
#ifdef _UNICODE
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlDSDU.lib")
#pragma message("Automatically linking with XListCtrlDSDU.lib")
#else
#pragma comment(lib,"XListCtrlDSRU.lib")
#pragma message("Automatically linking with XListCtrlDSRU.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlDSDA.lib")
#pragma message("Automatically linking with XListCtrlDSDA.lib")
#else
#pragma comment(lib,"XListCtrlDSRA.lib")
#pragma message("Automatically linking with XListCtrlDSRA.lib")
#endif
#endif
#elif !defined _AFXDLL && defined XLISTCTRLLIB_STATIC
// MFC static lib with XListCtrl static lib
#ifdef _UNICODE
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlSSDU.lib")
#pragma message("Automatically linking with XListCtrlSSDU.lib")
#else
#pragma comment(lib,"XListCtrlSSRU.lib")
#pragma message("Automatically linking with XListCtrlSSRU.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib,"XListCtrlSSDA.lib")
#pragma message("Automatically linking with XListCtrlSSDA.lib")
#else
#pragma comment(lib,"XListCtrlSSRA.lib")
#pragma message("Automatically linking with XListCtrlSSRA.lib")
#endif
#endif
#else
#pragma message(" ")
#pragma message("-------------------------------------" +
"-------------------------------------")
#pragma message(" The SD build configuration (MFC static," +
" XListCtrl DLL) is not available. ")
#pragma message("-------------------------------------" +
"-------------------------------------")
#pragma message(" ")
#error This build configuration is not available.
#endif
#endif
| XListCtrl Library Naming Conventions | ||||||||
|---|---|---|---|---|---|---|---|---|
| Library Name | MFC | XListCtrl | Build | Charset | ||||
| DLL | Static | DLL | Static | Debug | Release | ANSI | UNICODE | |
| XListCtrlDDDA |
|
|
|
|
||||
| XListCtrlDDDU |
|
|
|
| ||||
| XListCtrlDDRA |
|
|
|
|
||||
| XListCtrlDDRU |
|
|
|
| ||||
| XListCtrlDSDA |
|
|
|
|
||||
| XListCtrlDSDU |
|
|
|
| ||||
| XListCtrlDSRA |
|
|
|
|
||||
| XListCtrlDSRU |
|
|
|
| ||||
| XListCtrlSSDA |
|
|
|
|
||||
| XListCtrlSSDU |
|
|
|
| ||||
| XListCtrlSSRA |
|
|
|
|
||||
| XListCtrlSSRU |
|
|
|
| ||||
| XListCtrlSDxx | ��� not built ��� | |||||||
To build the XListCtrl libraries, go to Build | Batch Build and select the libraries you wish to build:

Then click on Rebuild All and the libraries will be built. By default, the .lib and .dll files are copied to the bin directory.
CListCtrl::LockWindowUpdate()/CListCtrl::UnlockWindowUpdate() to bracket the updating code.
CListCtrl::SetRedraw(FALSE)/CListCtrl::SetRedraw(TRUE) to bracket the updating code. After using one of these methods, you probably should call list.UpdateWindow() to make sure control is updated. If one method doesn't completely eliminate flickering in your application, try other method to determine which works best.
CListCtrl::EnableToolTips(TRUE).
LVS_EX_FULLROWSELECT style. This version includes many bug fixes that have been accumulating. My thanks for all who have reported bugs. Please try this new version and let me know if you find any bugs, or have suggestions for future enhancements.
#define DO_NOT_INCLUDE_XCOMBOLIST
If you insert this define, you do not need to include XComboList.cpp or XComboList.h in your project.
CXComboList::SetActive to accept scroll bar width as input parameter.
NM_CLICK and LVN_COLUMNCLICK to use ON_NOTIFY_REFLECT_EX(), to allow parent to handle message also (suggested by bkupcins).
XHeaderCtrl caused when XP theming is enabled. The GetHeaderCheckedState()/SetHeaderCheckedState() functions now use 0 = no check box, 1 = unchecked check box, 2 = checked check box. Note: The checkboxes.bmp file has also been updated, and must be replaced in all project that use 1.3 XListCtrl. The new defines XHEADERCTRL_NO_IMAGE, XHEADERCTRL_UNCHECKED_IMAGE, and XHEADERCTRL_CHECKED_IMAGE should be used when setting the image in the header control (see XListCtrlTestDlg.cpp for example).
GetSysColor() with class variables that are set in ctor. Class variables are reloaded in response to WM_SYSCOLORCHANGE message (suggested by KarstenK).
LVS_EX_FULLROWSELECT style.
XListCtrl will send to its parent when combo box selection is changed (WM_XLISTCTRL_COMBO_SELECTION) and when check box is clicked (WM_XLISTCTRL_CHECKBOX_CLICKED). The sample app shows how to handle these new messages.
CListCtrl::EnableToolTips(TRUE). If you #define constant NO_XLISTCTRL_TOOL_TIPS, the tooltip support will not be included. New API's for tooltips: BOOL SetItemToolTipText(int nItem, int nSubItem, LPCTSTR lpszToolTipText); CString GetItemToolTipText(int nItem, int nSubItem); void DeleteAllToolTips();
CXListCtrl is created dynamically via Create() instead of via dialog template. See XListCtrlTestDlg.cpp for details on how to convert the demo project to create CXListCtrl dynamically.
GetCurSel and SetCurSel to make coding easier. The CXListCtrl code is based on:
The city population figures are taken from Th. Brinkhoff: The Principal Agglomerations of the World.
This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Sep 2006 Editor: Smitha Vijayan |
Copyright 2002 by Hans Dietrich Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |