A combo box control is used with the SftBox_xxx functions or the C++ class CSftBox. In addition, the following standard Windows messages can be sent to a combo box control by an application. The messages are sent to the combo box control window; the combo box control passes them on to its static portion, edit control portion and dropdown portion as needed.
| Message | Description |
|---|---|
| WM_SETFONT, WM_GETFONT | Sets or retrieves the default font. |
| WM_SETTEXT, WM_GETTEXT, WM_GETTEXTLENGTH | Sets or retrieves the text of the combo box control. |
| WM_SETREDRAW | Suspends or resumes redrawing while items are added or modified. |
| WM_ENABLE | The combo box control has been enabled or disabled. |
| WM_CLEAR, WM_COPY, WM_CUT, WM_PASTE, WM_UNDO | Clipboard and editing operations. |
| WM_CANCELMODE | Cancels the operation in progress. |
| WM_PRINT, WM_PRINTCLIENT | Renders the combo box control into a device context. |
| WM_SETTINGCHANGE | Must be forwarded to the combo box control by its parent window to follow the Windows dark mode and high contrast settings. |
The following messages are not used by a combo box control:
| Message | Description |
|---|---|
| CB_xxx Messages | The messages and notifications of the standard Windows combo box. |
| WM_CONTEXTMENU | Context menu requests are reported as notifications. |
| WM_CTLCOLORxxx | Colors are defined using SetCtlColors. |
The WM_SETFONT message defines the default font used by the combo box control.
hFont = (HFONT) wParam;
The font handle.
fRedraw = (BOOL) LOWORD(lParam);
Set to TRUE to redraw the combo box control, FALSE otherwise.
The font is used by the static portion, the dropdown portion and the edit control portion of the combo box control. A different font for the edit control portion can be defined using SetEditCtlFont after the WM_SETFONT message has been sent, as WM_SETFONT replaces the edit control font.
The height of a combo box control depends on the font used. The combo box control may change the height of its window when the font changes (see SFTBOXN_SIZECHANGED).
The font is owned by the application and must remain valid until the combo box control is destroyed or another font is set.
An application should send a WM_SETFONT message with a font of the appropriate size when it receives the SFTBOXN_DPI_CHANGED notification.
The WM_GETFONT message returns the handle of the default font used by the combo box control, as defined using WM_SETFONT.
The WM_SETTEXT message (or the Windows API SetWindowText) sets the text of the edit control portion of a simple or dropdown combo box.
In a simple or dropdown combo box, the new text is handled like text entered by the user: SFTBOXN_EDITCHANGE is sent and, depending on the edit search mode (see SetEditSearchMode), the selected item may change. This does not apply if the edit control portion is a multi-line edit control (the first displayed column uses the SFTBOX_WRAP style).
In a dropdown list combo box, which has no edit control portion, WM_SETTEXT does not change the selected item or the contents of the static portion. Use SetCurSel or SelectString to select an item instead.
The WM_GETTEXT message (or the Windows API GetWindowText) retrieves the text of the combo box control.
In a simple or dropdown combo box, the text of the edit control portion is returned.
In a dropdown list combo box, the cell text of column 0 of the selected item is returned, even if the columns have been reordered. If there is no selected item, an empty string is returned.
The WM_GETTEXTLENGTH message (or the Windows API GetWindowTextLength) returns the length of the text of the combo box control, in characters, not including the terminating '\0'.
In a simple or dropdown combo box, the length of the text of the edit control portion is returned. In a dropdown list combo box, the length of the cell text of column 0 of the selected item is returned, or 0 if there is no selected item.
The WM_SETREDRAW message allows changes to the combo box control to be redrawn or prevents changes from being redrawn.
fRedraw = (BOOL) wParam;
Set to FALSE to suspend redrawing, TRUE to resume redrawing.
An application adding or modifying many items can send WM_SETREDRAW with fRedraw set to FALSE before making the changes and with fRedraw set to TRUE afterwards. When redrawing is resumed, the combo box control recalculates its dimensions and is redrawn completely. While redrawing is suspended, the dropdown portion is not redrawn and the combo box control does not adjust its height to its contents. The static portion and the edit control portion are still updated.
The WM_ENABLE message is received by the combo box control when it is enabled or disabled using the Windows API EnableWindow.
When a combo box control is enabled or disabled, its dropdown portion is hidden (dropdown and dropdown list combo boxes) and the combo box control is redrawn to reflect its new state. The static portion, the edit control portion and, in a simple combo box, the dropdown portion are enabled or disabled with the combo box control. A disabled combo box control is drawn disabled: the items are drawn using the grayed colors of the SFTBOX_COLORS structure (for example colorFgGrayed and colorTreeLinesGrayed, see SetCtlColors) and the edit control portion shows its text grayed.
The WM_CLEAR message deletes the selected text of the edit control portion, or removes the selection of a dropdown list combo box.
In a simple or dropdown combo box, the text selected in the edit control portion is deleted. The change is handled like text deleted by the user: SFTBOXN_EDITCHANGE is sent and, depending on the edit search mode (see SetEditSearchMode), the selected item may change.
In a dropdown list combo box, the combo box control no longer has a selected item after WM_CLEAR (the equivalent of SetCurSel with an index of -1).
The Clear function sends this message.
The WM_COPY message copies text to the clipboard.
In a simple or dropdown combo box, the text selected in the edit control portion is copied to the clipboard.
In a dropdown list combo box, the cell text of the selected item is copied to the clipboard. The text of the first displayed column is used.
The Copy function sends this message.
The WM_CUT message copies text to the clipboard and removes it from the combo box control.
In a simple or dropdown combo box, the text selected in the edit control portion is copied to the clipboard and deleted from the edit control portion.
In a dropdown list combo box, the cell text of the selected item is copied to the clipboard (see WM_COPY) and the selection is removed, so the combo box control has no selected item. The item itself is not deleted.
The Cut function sends this message.
The WM_PASTE message inserts the text on the clipboard into the edit control portion of a simple or dropdown combo box.
WM_PASTE has no effect in a dropdown list combo box. The Paste function sends this message.
The WM_UNDO message undoes the last editing operation in the edit control portion of a simple or dropdown combo box.
WM_UNDO has no effect in a dropdown list combo box.
The WM_CANCELMODE message cancels an operation in progress, such as a drag & drop operation or the mouse capture.
An application can send a WM_CANCELMODE message to the combo box control while handling certain notifications to cancel the default processing:
Sending WM_CANCELMODE during a drag & drop operation ends the operation; the parent window receives a SFTBOXN_CANCELDRAG notification.
The WM_PRINT message renders the combo box control into the specified device context.
The combo box control supports the WM_PRINT and WM_PRINTCLIENT messages, so its current appearance can be rendered into a device context provided by the application, for example a memory device context. The static portion and the edit control portion are included, in a simple combo box also the dropdown portion. The dropdown portion of a dropdown or dropdown list combo box is not included.
The WM_PRINTCLIENT message renders the client area of the combo box control into the specified device context (see WM_PRINT).
The WM_SETTINGCHANGE message informs the combo box control that a Windows system setting has changed.
Windows sends the WM_SETTINGCHANGE message to top-level windows only. When the dark mode setting is SFTBOX_DARKMODE_AUTO (see SetDarkMode) or the high contrast setting is SFTBOX_HIGHCONTRAST_AUTO (see SetHighContrastMode), the parent window must forward the message to the combo box control. The combo box control then updates its appearance and sends a SFTBOXN_DARKMODE_CHANGED or SFTBOXN_HIGHCONTRAST_CHANGED notification if the active state changed (see Dark Mode and High Contrast).
SftBox/DLL is not based on the standard Windows combo box. The messages of the standard Windows combo box (CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_SHOWDROPDOWN, etc.) are not processed by a combo box control. The SftBox_xxx functions (AddString, GetCurSel, SetCurSel, ShowDropDown, etc.) or the equivalent member functions of the C++ class CSftBox are used instead.
The notifications of the standard Windows combo box (CBN_SELCHANGE, CBN_DROPDOWN, etc.) are not sent. A combo box control sends its own notifications, such as SFTBOXN_SELCHANGE and SFTBOXN_DROPDOWN.
An application does not handle the WM_CONTEXTMENU message to implement context menus for a combo box control. A context menu request is reported to the parent window using the notifications SFTBOXN_CONTEXTMENU_STATIC, SFTBOXN_CONTEXTMENU_EDIT and SFTBOXN_CONTEXTMENU_DD (mouse) or SFTBOXN_CONTEXTMENU_KBD_STATIC, SFTBOXN_CONTEXTMENU_KBD_EDIT and SFTBOXN_CONTEXTMENU_KBD_DD (keyboard), depending on the portion of the combo box control for which the context menu is requested.
A standard Windows combo box sends WM_CTLCOLORxxx messages to its parent window to obtain its colors. These messages are not used to define the colors of a combo box control. All colors are defined using SetCtlColors, SetCellInfo, SetRowInfo and SetColumns.
See Also C/C++ API | Categories | Notifications