You create a list box child window control with CreateWindow using ”listbox“ as the window class and WS_CHILD as the window style. However, this default list box style does not send WM_COMMAND messages to its parent, meaning that a program would have to interrogate the list box (via messages to the list box controls) regarding the selection of items within the list box. Therefore, list box controls almost always include the list box style identifier LBS_NOTIFY, which allows the parent window to receive WM_COMMAND messages from the list box. If you want the list box control to sort the items in the list box, you can also use LBS_SORT, another common style.
By default, list boxes are single selection. Multiple-selection list boxes are relatively rare. If you want to create one, you use the style LBS_MULTIPLESEL.
Normally, a list box updates itself when a new item is added to the scroll box list. You can prevent this by including the style LBS_NOREDRAW. You will probably not want to use this style, however. Instead, you can temporarily prevent repainting of a list box control by using the WM_SETREDRAW message that I'll describe a little later.
By default, the list box window procedure displays only the list of items without any border around it. You can add a border with the window style identifier WS_BORDER. And to add a vertical scroll bar for scrolling through the list with the mouse, you use the window style identifier WS_VSCROLL.
WINDOWS.H defines a list box style called LBS_STANDARD that includes the most commonly used styles. It is defined as:
(LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER)
You can also use the WS_SIZEBOX and WS_CAPTION identifiers, but these will allow the user to resize the list box and to move it around its parent's client area.
The width of a list box should accommodate the width of the longest string plus the width of the scroll bar. You can get the width of the vertical scroll bar using:
GetSystemMetrics (SM_CXVSCROLL) ;
You can calculate the height of the list box by multiplying the height of a character by the number of items you want to appear in view. A list box does not use tmExternalLeading when spacing lines of text.