Implementing Alphanumeric Ordering

Copyright © 2011 by David Wincelberg

I made some changes to the source code described in my October 2000 Dr. Dobb's Journal article in response to suggestions from a reader. Click for the revised source code. This source code and the samples below may be used in any program, including commercial ones. Please credit me in your program's help file or documentation.

MFC Controls Samples (Visual C++ 6.0)

In the following image, the list boxes show the differences between alphabetic, simple alphanumeric and full alphanumeric ordering. Running SortTest will show these differences also in check list boxes, list controls, combo boxes, tree controls and owner-draw list boxes. SortText.exe is in the Release folder of SortTest.zip.

SortTest: shows different sort orders in various controls

Download

SortTest.zip (121 KB)
This archive contains many of the SortTest source code files. The necessary window styles are listed in the comments in the Sort*.cpp files. In debug mode, the sort classes assert if required styles are absent or prohibited styles are present. This archive does not contain the files for full alphanumeric ordering. Those files are available in compiled or source-code form for various fees.

Instructions

To incorporate CSortListBox into a dialog box or a property page, put the following lines into the the dialog box's or property page's .H file.

#include "SortListBox.h"   // near the top of the file
CSortListBox m_listBox2;   // among the attributes

In the corresponding .CPP file, put the following line into OnInitDialog() before this control is referenced. Be sure to remove the corresponding variable from ClassWizard's list and to set the styles as indicated in SortListBox.cpp.

m_listBox2.SubclassDlgItem (IDC_LIST2, this);

Here, the styles are:

Optional: sort, horizontal scroll, vertical scroll
Do not select: owner-draw (fixed or variable)

Note that sorting can be turned off by removing the sort style. This list-box class also handles adjusting the horizontal extent.

The instructions for incorporating the other controls into an application are similar.

Changes

See the changes page for a list of SortTest improvements.


david dot wincelberg at gmail dot com
(In the above line, change "at" and "dot" to their symbols and remove the spaces to produce my e-mail address.)

Return to main page
Last updated: 25-May-2011