I've been saving the best for last: LB_DIR, the most powerful list box message. This fills the list box with a file directory list, optionally including subdirectories and valid disk drives:
SendMessage (hwndList, LB_DIR, wAttr, (LONG) lpszFileSpec) ;
The wAttr parameter is a file attribute code. The least significant byte is the normal file attribute code when making MS-DOS function calls:
wAttr | Attribute |
0x0000 | Normal file |
0x0001 | Read-only file |
0x0002 | Hidden file |
0x0004 | System file |
0x0010 | Subdirectory |
0x0020 | File with archive bit set |
The high byte provides some additional control over the items desired:
wAttr | Option |
0x4000 | Include drive letters |
0x8000 | Exclusive search only |
When the wAttr value of the LB_DIR message is 0x0000, the list box lists normal files, read-only files, and files with the archive bit set. This is consistent with the logic used by MS-DOS function calls to find files. When the value is 0x0010, the list includes child subdirectories in addition to these files; this list is the equivalent of that displayed by the Directory command or by Windows' File Manager. A value of 0x4010 expands the 0x0010 list to include all valid drives; for many Windows programs, this is the list in the dialog box called up by selecting Open from the program's File menu. To list all files, child subdirectories, and drives, you set the wAttr value to 0x4037.
Setting the topmost bit of wAttr lists the files with the indicated flag while excluding normal files. For a Windows file backup program, for instance, you might want to list only files that have been modified since the last backup. Such files have their archive bits set, so you would use 0x8020. A value of 0x8010 lists only subdirectories; 0xC000, only valid disk drives; and 0xC010, subdirectories and valid disk drives but no files.
The lParam parameter is a far pointer to a file specification string such as "*.*". This file specification does not affect the subdirectories that the list box includes.
You'll want to use the LBS_SORT message for list boxes with file lists. The list box will first list files satisfying the file specification and then (optionally) list valid disk drives in the form:
[-A-]
and (also optionally) subdirectory names. The first subdirectory listing will take the form:
[..]
This ”double-dot“ subdirectory entry lets the user back up one level toward the root directory. (The entry will not appear if you're listing files in the root directory.) Finally, the specific subdirectory names are listed in the form:
[SUBDIR]
If you do not use LBS_SORT, the filenames and subdirectory names are intermixed and the drive letters appear at the bottom of the list box.