4.3.3 Monitoring List Box Controls in an Open or Save As Dialog Box

An application can monitor list box selections in order to process and display data in custom controls. For example, an application can use a custom control to display the total length, in bytes, of all of the files selected in the File Name box. One method the application can use to obtain this value is to recompute the total count of bytes each time the user selects a file or cancels the selection of a file. A faster method is for the application to use the LBSELCHSTRING message to identify a new selection and add the corresponding file length to the value that appears in the custom control. (Note that in this example, the custom control is a standard Windows control that you identify in a resource file template for one of the common dialog boxes.)

An application registers the selection-change message with the RegisterWindowMessage function. Once the application registers the message, it uses this function's return value to identify messages from the dialog box. The message is processed in the application-supplied hook function for the common dialog box. The wParam parameter of each message identifies the list box in which the selection occurred. The low-order word of the lParam parameter identifies the list box item. The high-order word of the lParam parameter is one of the following values:

Value Meaning

CD_LBSELCHANGE Specifies that the item identified by the low-order word of lParam was the item in a single-selection list box.
CD_LBSELSUB Specifies that the item identified by the low-order word of lParam is no longer selected in a multiple-selection list box.
CD_LBSELADD Specifies that the item identified by the low-order word of lParam was selected from a multiple-selection list box.
CD_LBSELNOITEMS Specifies that no items exist in a multiple-selection list box.

For an example that registers a common dialog box message, see Section 4.5, “Using Find and Replace Dialog Boxes.”