The following window styles are available for a combo box control, in addition to the standard window styles (such as WS_CHILD, WS_VISIBLE, WS_TABSTOP, etc.). The window styles are specified when the combo box control is created, using CreateWindow, CreateWindowEx or in a dialog resource.
| Window Style | Value | Can be changed after creation |
|---|---|---|
| SFTBOXSTYLE_SIMPLE | 0x0000L | No |
| SFTBOXSTYLE_DROPDOWN | 0x0100L | No |
| SFTBOXSTYLE_DROPDOWNLIST | 0x0200L | No |
| SFTBOXSTYLE_DISABLENOSCROLL | 0x0001L | No (use SetDisableNoScroll) |
| SFTBOXSTYLE_LEFTBUTTONONLY | 0x0020L | No |
| SFTBOXSTYLE_VARIABLE | 0x0080L | No |
| SFTBOXSTYLE_ALIGNBOTTOM | 0x0400L | Yes |
| SFTBOXSTYLE_ALIGNCENTER | 0x0800L | Yes |
| SFTBOXSTYLE_AUTOHSCROLL | 0x1000L | No |
Styles that can be changed after the combo box control has been created are changed using the Windows API SetWindowLong(hwnd, GWL_STYLE, style).
Defines a simple combo box. A simple combo box has an edit control portion and a dropdown portion, which is always displayed below the edit control portion. It has no dropdown button.
Defines a dropdown combo box. A dropdown combo box has an edit control portion and a dropdown button. The dropdown portion is displayed when the user clicks the dropdown button and is hidden once an item has been selected.
Defines a dropdown list combo box. A dropdown list combo box has a static portion, which displays the selected item, and a dropdown button. The dropdown portion is displayed when the user clicks the dropdown button and is hidden once an item has been selected. A dropdown list combo box has no edit control portion.
SFTBOXSTYLE_SIMPLE, SFTBOXSTYLE_DROPDOWN and SFTBOXSTYLE_DROPDOWNLIST are mutually exclusive and define the basic style of the combo box control. SFTBOXSTYLE_MASK is not a window style. It is a mask that can be used to extract the basic style from the window styles of a combo box control:
DWORD style = GetWindowLong(hwndCtl, GWL_STYLE) & SFTBOXSTYLE_MASK;
if (style == SFTBOXSTYLE_DROPDOWNLIST) {
// dropdown list combo box
}The basic style is evaluated when the combo box control is created and cannot be changed afterwards.
When this style is selected, the scroll bars of the dropdown portion are disabled when scrolling is not possible. Without this style, scroll bars are hidden when scrolling is not possible. This style is evaluated when the combo box control is created only. Use SetDisableNoScroll to change this setting after the combo box control has been created. The size box of the dropdown portion (see SetSizeBox) is only available in a dropdown or dropdown list combo box created with the WS_VSCROLL and WS_HSCROLL styles, while scroll bars that are not needed are shown disabled (this style or SetDisableNoScroll).
When this style is selected, the static portion and the dropdown portion ignore the middle and right mouse buttons, so no middle or right mouse button notifications are sent to the parent window. The context menu notifications (such as SFTBOXN_CONTEXTMENU_DD) are still sent when the right mouse button is clicked. Without this style, clicking an item in the dropdown portion of a dropdown or dropdown list combo box with the middle mouse button accepts the item and hides the dropdown portion, just like the left mouse button. The right mouse button selects the item but leaves the dropdown portion displayed. This style is evaluated when the combo box control is created only.
Defines a variable height combo box control, where the height of each item varies based on the fonts, pictures, lines of text, word wrapping and other attributes used. In a variable height combo box control each item can have a different height based on its attributes. If this style is not specified, all items have the same height. This style is evaluated when the combo box control is created only.
A dropdown or dropdown list combo box automatically adjusts the height of its window to its contents. By default, the top edge of the combo box control remains in place and the bottom edge moves. When the SFTBOXSTYLE_ALIGNBOTTOM style is selected, the bottom edge of the combo box control remains in place and the top edge moves instead.
When this style is selected and a dropdown or dropdown list combo box adjusts the height of its window, the combo box control remains vertically centered around its current position, so both the top and the bottom edge move. If both SFTBOXSTYLE_ALIGNCENTER and SFTBOXSTYLE_ALIGNBOTTOM are specified, SFTBOXSTYLE_ALIGNCENTER is used.
SFTBOXSTYLE_ALIGNMASK is not a window style. It is a mask that can be used to extract the alignment styles SFTBOXSTYLE_ALIGNBOTTOM and SFTBOXSTYLE_ALIGNCENTER from the window styles of a combo box control.
When this style is selected, the edit control portion of a simple or dropdown combo box automatically scrolls its text horizontally when the user enters text beyond the end of the edit control (the equivalent of the edit control style ES_AUTOHSCROLL). Without this style, the text that can be entered is limited to the width of the edit control portion. This style is evaluated when the edit control portion is created, so it should be specified when the combo box control is created.
This style is reserved and should not be used.
The following standard window styles have a special meaning for a combo box control.
| Window Style | Description |
|---|---|
| WS_VSCROLL | The dropdown portion has a vertical scroll bar, which is used when the dropdown portion cannot display all items. Without this style, the dropdown portion has no vertical scroll bar. This style is evaluated when the combo box control is created only. |
| WS_HSCROLL | The dropdown portion has a horizontal scroll bar, which is used when the dropdown portion is not wide enough to display all columns (see SetHorizontalExtent). Without this style, the dropdown portion has no horizontal scroll bar. This style is evaluated when the combo box control is created only. |
| WS_BORDER | The combo box control has a border. If WS_BORDER is specified without the extended window style WS_EX_CLIENTEDGE, the border style SFTBOX_BORDER_FLAT is used. If the extended window style WS_EX_CLIENTEDGE is specified (with or without WS_BORDER), the border style SFTBOX_BORDER_CLIENT is used. If neither style is specified, the combo box control has no border (SFTBOX_BORDER_NONE). These styles are evaluated when the combo box control is created only. The border is drawn by the combo box control itself, so the styles are no longer part of the window styles once the combo box control has been created. The border style can be changed later using SetControlInfo (see SFTBOX_CONTROL, iBorderStyle). |
| WS_TABSTOP | The user can move the input focus to the combo box control using the TAB key (in a dialog). When the combo box control receives the input focus, the edit control portion (simple and dropdown combo boxes) or the static portion (dropdown list combo box) receives the input focus. |
The window styles WS_VSCROLL, WS_HSCROLL and SFTBOXSTYLE_DISABLENOSCROLL describe the scroll bars of the dropdown portion. They are no longer part of the window styles of the combo box control window once it has been created.
See Also C/C++ API | Categories | Notifications