BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
dwStyle
Specifies the style of the combo box.
rect
Points to the position and size of the combo box. Can be a RECT structure or a CRect object.
pParentWnd
Specifies the combo box's parent window (usually a CDialog or CModalDialog). It must not be NULL.
nID
Specifies the combo box's resource ID.
You construct a CComboBox object in two steps. First call the constructor, then call Create, which creates the Windows combo box and attaches it to the CComboBox object.
When Create executes, Windows sends the WM_NCCREATE, WM_CREATE, WM_NCCALCSIZE, and WM_GETMINMAXINFO messages to the combo box.
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 CComboBox, 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 CComboBox object to its parent, add any of the following message-map entries that you want processed to the parent-class message map:
ON_COMMAND
ON_CBN_KILLFOCUS
ON_CBN_SETFOCUS
ON_CBN_DROPDOWN
ON_CBN_DBLCLK
ON_CBN_ERRSPACE
ON_CBN_SELCHANGE
ON_CBN_EDITCHANGE
ON_CBN_EDITUPDATE
Apply the following window styles to a combo-box control:
Style | Application |
WS_CHILD | Always. |
WS_VISIBLE | Usually. |
WS_DIABLED | Rarely. |
WS_VSCROLL | For list boxes and combo boxes. |
WS_HSCROLL | For list boxes and combo boxes. |
WS_GROUP | To group controls. |
WS_TABSTOP | To include the combo box in the tabbing order. |
See CreateEx in the CWnd base class for a full description of these window styles.
Use any combination of the following combo-box styles for dwStyle:
Style | Description |
CBS_AUTOHSCROLL | Automatically scrolls the text in the edit control to the right when the user types a character at the end of the line. If this style is not set, only text that fits within the rectangular boundary is allowed. |
CBS_DROPDOWN | Similar to CBS_SIMPLE, except that the list box is not displayed unless the user selects an icon next to the edit control. |
CBS_DROPDOWNLIST | Similar to CBS_DROPDOWN, except that the edit control is replaced by a static text item that displays the current selection in the list box. |
CBS_HASSTRINGS | An owner-draw combo-box contains items consisting of strings. The combo 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. |
CBS_OEMCONVERT | Text entered in the combo-box edit control is converted from the ANSI character set to the OEM character set and then back to ANSI. This ensures proper character conversion when the application calls the AnsiToOem Windows function to convert an ANSI string in the combo box to OEM characters. This style is most useful for combo boxes that contain filenames and applies only to combo boxes created with the CBS_SIMPLE or CBS_DROPDOWN styles. |
CBS_OWNERDRAWFIXED | The owner of the list box is responsible for drawing its contents; the items in the list box are all the same height. |
CBS_OWNERDRAWVARIABLE | The owner of the list box is responsible for drawing its contents; the items in the list box are variable in height. |
CBS_SIMPLE | The list box is displayed at all times. The current selection in the list box is displayed in the edit control. |
CBS_SORT | Automatically sorts strings entered into the list box. |
Returns TRUE if successful; otherwise FALSE.