Color List Box With Extra Bits | CodeGuru

Color List Box With Extra Bits

Environment: Developed using VC6, tested on Win2k Pro and XP Pro. This MFC CListBox class extension is result of searching for a listbox that does exactly what I have implemented here, except for the vertical alignment. After browsing through CodeGuru site, I found some code but none that fully matched my project needs. Still, all […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 30, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment:

Developed using VC6, tested on Win2k Pro and XP Pro.

This MFC CListBox class extension is result of searching for a listbox that does exactly what I have implemented here, except for the vertical alignment. After browsing through CodeGuru site, I found some code but none that fully matched my project needs. Still, all the credit to Patrice Godard and Paul M. Meidinger for designing CColorListBox class, found at
https://www.codeguru.com/listbox/colorlb.shtml
, that I got the idea from.

CListBoxEBX Features

  • Background color.
  • Foreground color.
  • Text horizontal alignment.
  • Text vertical alignment.
  • Indicating inactive items.
  • Hooking of a DWORD value per item as in original SetItemData().
  • Allows for setting of the items height

Future desired features

  • Font manipulation.
  • Use of images
  • Horizontal scrolling.

// Instantiate the wrapper for the list box window
CListBoxEBX m_xList;
// This can be inserted in the ::OnInitDialog()
m_xList.SetItemHeight(40);
m_xList.AddItem(“First string”);
m_xList.AddItem(“Last string”);
m_xList.InsertItem(“Middle string #1”, 1, RGB(50,  100, 150),
                                          RGB(255, 255,255));
m_xList.InsertItem(“Middle string #2”, 1, RGB(100, 150, 200),
                                          RGB(255, 255,255));
m_xList.InsertItem(“Middle string #3”, 1, 12432321,
                                          RGB(255, 255,255));
m_xList.SetActive(FALSE, 2);
m_xList.SetCurSel(0);

Downloads

Download demo project – 20 Kb

Download source – 5 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.