February 24th, 2010

Why does the CBS_SORT combo box style sort the left square bracket so strangely?

Some time ago, Michael Kaplan asked (and answered), How the @#%&*! does CBS_SORT choose to sort it all out? One detail in his answer is that the sorting algorithm used by CBS_SORT is basically CompareString, with special treatment for the left square bracket U+005B. Why is the left square bracket so special? It goes back to the LB_DIR message (which is in turn used by DlgDirList, CB_DIR, DlgDirListComboBox, and related functions). If you ask for drives to be added to the list or combo box, they are added in the form [-X-], where X is the drive letter. The left square bracket is special-cased so that the drive letters sort to the top of the list.

Of course, LB_DIR and related functions and messages are pretty old-school nowadays, but the code for them is still around, so the sort function still needs to worry about them.

Topics
History

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.