BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
dwStyle
Specifies the style of the list box.
rect
Specifies the list-box size and position. Can be either a CRect object or a RECT structure.
pParentWnd
Specifies the list box's parent window (usually a CDialog or CModalDialog object). It must not be NULL.
nID
Specifies the list box's resource ID.
You construct a CListBox object in two steps. First call the constructor, then call Create, which initializes the Windows list box and attaches it to the CListBox object.
When Create executes, Windows sends the WM_NCCREATE, WM_CREATE, WM_NCCALCSIZE, and WM_GETMINMAXINFO messages to the list-box control.
These messages are handled by default by the OnNcCreate, OnCreate, OnNcCalcSize, and OnGetMinMaxInfo member functions in the CWnd base class. To extend the default message handling, derive a class from CListBox, add a message map to the new class, and override the preceding message-handler member functions. Override OnCreate, for example, to perform needed initialization for a new class.
To handle Windows notification messages sent from a CListBox object to its parent, add any of the following message-map entries that you want to process to the parent class message map:
ON_COMMAND
ON_LBN_DBLCLK
ON_LBN_ERRSPACE
ON_LBN_KILLFOCUS
ON_LBN_SELCHANGE
ON_LBN_SETFOCUS
Apply the following window styles to a list-box control:
Style | Application |
WS_CHILD | Always. |
WS_VISIBLE | Usually. |
WS_DISABLED | Rarely. |
WS_VSCROLL | Adds a vertical scroll bar. |
WS_HSCROLL | Adds a horizontal scroll bar. |
WS_GROUP | To group controls. |
WS_TABSTOP | To allow tabbing to this control. |
See CreateEx in the CWnd base class for a full description of these window styles.
Use any combination of the following list-box styles for dwStyle:
Style | Meaning |
LBS_EXTENDEDSEL | The user can select multiple items using the SHIFT key and the mouse or special key combinations. |
LBS_HASSTRINGS | Specifies an owner-draw list box that contains items consisting of strings. The list box maintains the memory and pointers for the strings so the application can use the GetText member function to retrieve the text for a particular item. |
LBS_MULTICOLUMN | Specifies a multicolumn list box that is scrolled horizontally. The SetColumnWidth member function sets the width of the columns. |
LBS_MULTIPLESEL | String selection is toggled each time the user clicks or double-clicks the string. Any number of strings can be selected. |
LBS_NOINTEGRALHEIGHT | The size of the list box is exactly the size specified by the application when it created the list box. Usually, Windows sizes a list box so that the list box does not display partial items. |
LBS_NOREDRAW | List-box display is not updated when changes are made. This style can be changed at any time by sending a WM_SETREDRAW message. |
LBS_NOTIFY | Parent window receives an input message whenever the user clicks or double-clicks a string. |
LBS_OWNERDRAWFIXED | The owner of the list box is responsible for drawing its contents; the items in the list box are the same height. |
LBS_OWNERDRAWVARIABLE | The owner of the list box is responsible for drawing its contents; the items in the list box are variable in height. |
LBS_SORT | Strings in the list box are sorted alphabetically. |
LBS_STANDARD | Strings in the list box are sorted alphabetically, and the parent window receives an input message whenever the user clicks or double-clicks a string. The list box contains borders on all sides. |
LBS_USETABSTOPS | Allows a list box to recognize and expand tab characters when drawing its strings. The default tab positions are 32 dialog units. (A dialog unit is a horizontal or vertical distance. One horizontal dialog unit is equal to one-fourth of the current dialog base width unit. The dialog base units are computed based on the height and width of the current system font. The GetDialogBaseUnits Windows function returns the current dialog base units in pixels.) |
LBS_WANTKEYBOARDINPUT | The owner of the list box receives WM_VKEYTOITEM or WM_CHARTOITEM messages whenever the user presses a key when the list box has input focus. This allows an application to perform special processing on the keyboard input. |
TRUE if successful; otherwise FALSE.