List boxes most commonly are used in dialog windows. A list box in a dialog box is a control window, like a push button or an entry field. Typically, the application defines a list box as one item in a dialog template in the resource-definition file, as shown in the following resource compiler source-code fragment.
DLGTEMPLATE IDD_OPEN BEGIN DIALOG "Open...", IDD_OPEN, 35, 35, 150, 135, FS_DLGBORDER, FCF_TITLEBAR BEGIN LISTBOX IDD_FILELIST, 15, 15, 90, 90 PUSHBUTTON "Drive", IDD_DRIVEBUTTON, 115, 70, 30, 14 DEFPUSHBUTTON "Open", IDD_OPENBUTTON, 115, 40, 30, 14 PUSHBUTTON "Cancel", IDD_CANCELBUTTON, 115, 15, 30, 14 END END
Once the dialog resource is defined, the application loads and displays the dialog box as it would normally. The application inserts items into the list when processing the WM_INITDLG message.
A dialog window with a list box usually has an OK button. The user can select items in the list, and then indicate a final selection by double-clicking, pressing Enter, or clicking the OK button. When the dialog-window procedure receives a message indicating that the user has clicked the OK button, it queries the list box to determine the current selection (or selections, if the list allows multiple selections), and then responds as though it had received a WM_CONTROL message with the LN_ENTER notification code.