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

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon